Code: Select all
from machine import Pin
button = Pin(0, Pin.IN)
lastState = 0 #Variable created here
def buttonPress():
tempState = button.value()
if (lastState == 0) and (tempState == 1): #Error on this line
lastState = tempState
return 1
elif (lastState == 1) and (tempState == 1):
lastState = tempState
return 2
elif (lastState == 1) and (tempState == 0):
lastState = tempState
return 3
else:
return 0
while True:
print(buttonPress())
Can someone help me with the error? Also tell me if there is a better way to do this