safwan092

Untitled

Dec 14th, 2021
1,473
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.03 KB | None | 0 0
  1. import RPi.GPIO as GPIO
  2. import webbrowser
  3. import time
  4. import RPi.GPIO as GPIO
  5.  
  6. GPIO.setwarnings(False)
  7. GPIO.setmode(GPIO.BCM)
  8.  
  9. onPin = 27
  10. offPin = 22
  11. state1 = 0
  12. state2 = 0
  13.  
  14. GPIO.setup(onPin,GPIO.IN)
  15. GPIO.setup(offPin,GPIO.IN)
  16.  
  17.  
  18. while True:
  19.         if GPIO.input(onPin) == GPIO.HIGH:
  20.                 if state1 == 0:
  21.                         print("ON")
  22.                         webbrowser.open('http://192.168.48.251/H')
  23.                         state1 = 1
  24.                         time.sleep(0.5)
  25.         elif GPIO.input(onPin) == GPIO.LOW:
  26.                 if state1 == 1:
  27.                         state1 = 0
  28.                                          
  29.         if GPIO.input(offPin) == GPIO.HIGH:
  30.                 if state2 == 0:
  31.                         print("OFF")
  32.                         webbrowser.open('http://192.168.48.251/L')
  33.                         state2=1
  34.                         time.sleep(0.5)
  35.         elif GPIO.input(offPin) == GPIO.LOW:
  36.                 if state2 == 1:
  37.                         state2 = 0
  38.  
Advertisement
Add Comment
Please, Sign In to add comment