Refactored main loop
This commit is contained in:
parent
ad49985a12
commit
0b11e06e05
1 changed files with 14 additions and 5 deletions
19
main.py
19
main.py
|
@ -9,13 +9,22 @@ GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_UP)
|
||||||
GPIO.setup(24, GPIO.OUT)
|
GPIO.setup(24, GPIO.OUT)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
lastState = GPIO.input(23)
|
||||||
|
if lastState == False:
|
||||||
|
GPIO.output(24, True)
|
||||||
while True:
|
while True:
|
||||||
button_state = GPIO.input(23)
|
button_state = GPIO.input(23)
|
||||||
if button_state == False:
|
if button_state == lastState:
|
||||||
GPIO.output(24, True)
|
print('No Change...')
|
||||||
print('Button Pressed...')
|
|
||||||
time.sleep(0.2)
|
|
||||||
else:
|
else:
|
||||||
GPIO.output(24, False)
|
if button_state == False:
|
||||||
|
GPIO.output(24, True)
|
||||||
|
print('Button Pressed...')
|
||||||
|
else:
|
||||||
|
GPIO.output(24, False)
|
||||||
|
print('Button Released...')
|
||||||
|
lastState = button_state
|
||||||
|
time.sleep(0.02)
|
||||||
except:
|
except:
|
||||||
GPIO.cleanup()
|
GPIO.cleanup()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue