rpi-experiments/main.py

31 lines
723 B
Python
Raw Normal View History

2018-04-04 08:39:59 +00:00
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(24, GPIO.OUT)
try:
2018-04-04 16:41:53 +00:00
lastState = GPIO.input(23)
if lastState == False:
GPIO.output(24, True)
2018-04-04 08:39:59 +00:00
while True:
button_state = GPIO.input(23)
2018-04-04 16:41:53 +00:00
if button_state == lastState:
print('No Change...')
2018-04-04 08:39:59 +00:00
else:
2018-04-04 16:41:53 +00:00
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)
2018-04-04 08:39:59 +00:00
except:
GPIO.cleanup()
2018-04-04 16:41:53 +00:00