I have a small beginner question :D. I want to make the raspberry Pi sleep for 5 seconds and in this time i want him to check the status of a button and if the button is pressed he quits the waiting status imediatlly and continues with other stuff.

I tried it with time.sleep(5) but in this case he sleeps for 5 Seconds and does nothing. I also tried time_a = time.time() and then substract it but in this case my thonny python ide crashed for some reason...

Thank you for the Help!

  • Post the code that you tried using time (in code block) and any error message. – CoderMike Jan 21 '19 at 13:36
  • @CoderMike there were no error messages my IDE only showed the Outputs at the end of the programm therefore i thought that it didn t work but now i guess it does – benipro98 Jan 21 '19 at 13:39
  • Make sure you have at least a small sleep somewhere in your loop eg time.sleep(0.1) otherwise you may see 100% cpu usage. – CoderMike Jan 21 '19 at 13:45

Solution i guess: My IDE was to slow to print out that it was working. I tried the programm in the shell and there i saw the expected result. I did it with timer_a = time.time() and elapsed = time.time()-timer_a

| improve this answer | |
  • Please accept your own answer with a click on the tick on its left side. Only this will finish the question and it will not pop up again year for year. – Ingo Mar 3 at 13:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.