0

I manage to read the button, but my render_template is never executed as the while look is checking the button. How can I solve that problem?

@app.route("/")
def main():
   # For each pin, read the pin state and store it in the pins dictionary:
   for pin in pins:
      pins[pin]['state'] = GPIO.input(pin)

   GPIO.setup(20, GPIO.IN)

   while True:
      if GPIO.input(20):
         print("Button Pressed")
         print
         GPIO.input(20)
         sleep(.3)
      else:
         os.system('clear')  # clear the screens text
         print("Waiting for you to press a button")
         sleep(0.01)

   # Put the pin dictionary into the template data dictionary:
   templateData = {
      'pins': pins,
   }

   # Pass the template data into the template main.html and return it to the user
   return render_template('main.html', **templateData)
  • I had duplicated that question, so I deleted the other one. Thank you Aurora0001 and @jsotola to point it out. jsotola I will try to add a "exit" in the while loop as you had said. Cheers. – Thiago Farias Jul 25 '18 at 9:27

Your Answer

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

Browse other questions tagged or ask your own question.