Advertisement
Hobe

lab2_exercise1-2

Nov 15th, 2018
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.43 KB | None | 0 0
  1. import RPi.GPIO as GPIO
  2. import time
  3.  
  4. buttonPin = 11
  5. ledPin = 12
  6.  
  7. GPIO.setmode(GPIO.BOARD)
  8.  
  9. GPIO.setup(buttonPin, GPIO.IN)
  10. GPIO.setup(ledPin, GPIO.OUT)
  11. GPIO.output(ledPin, True)
  12. previous_state = 0
  13. led_state = False
  14.  
  15. while True:
  16.     input = GPIO.input(buttonPin)
  17.     if previous_state == 0 and input == 1:
  18.         led_state = not led_state
  19.         GPIO.output(ledPin, led_state)
  20.     previous_state = input
  21.     time.sleep(0.1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement