Following the RPI Education Manual
I am trying to check if the button has been pressed in a separate thread so i can continue the rest of my program, I have followed the Manual exactly but I must have missed something as I keep getting the error
Traceback (most recent call last): File "/home/pi/btnThreading2.py", line 8, in <module> class Button(threading.Thread): File "/home/pi/btnThreading2.py", line 36, in Button button = Button(36) NameError: name 'Button' is not defined
What did i do wrong?
import threading import time import RPi.GPIO as GPIO GPIO.setmode(GPIO.BOARD) class Button(threading.Thread): def __init__(self, channel): threading.Thread.__init__(self) self._pressed = False self.channel = channel GPIO.setup(self.channel, GPIO.IN) self.deamon = True self.start() def run(self): previous = None while 1: current = GPIO.input(self.channel) time.sleep(0.01) if current is False and previous is True: self._pressed = True while self._pressed: time.sleep(0.05) previous = current def onButtonPress(): print("btn presdsed") button = Button(36) while True: name = input('Enter a Name:') if name.upper() == ('Q'): break print('hello', name) if button.pressed(): onButtonPress()