Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/local/bin/python3
- import RPi.GPIO as GPIO
- import time
- import keyboard
- import curses
- import os
- GPIO.setmode(GPIO.BOARD)
- #define the pin that goes to the circuit
- pin_to_circuit = 7
- start = 0
- button_delay = 0.2
- def rc_time (pin_to_circuit):
- count = 0
- #Output on the pin for
- GPIO.setup(pin_to_circuit, GPIO.OUT)
- GPIO.output(pin_to_circuit, GPIO.LOW)
- time.sleep(0.1)
- #Change the pin back to input
- GPIO.setup(pin_to_circuit, GPIO.IN)
- #Count until the pin goes high
- while (GPIO.input(pin_to_circuit) == GPIO.LOW):
- count += 1
- return count
- #Catch when script is interrupted, cleanup correctly
- try:
- # Main loop
- while True:
- try:
- key = win.getkey()
- win.clear()
- win.addstr("Detected key:")
- win.addstr(str(key))
- print(key, os.linesep)
- except Exception as e:
- # No input
- pass
- value = rc_time(pin_to_circuit)
- if value < 8000 and start == 1:
- print ("DAY LIGHT", value)
- else:
- print ("Night LIGHT", value)
- except KeyboardInterrupt:
- pass
- finally:
- GPIO.cleanup()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement