Advertisement
Guest User

Untitled

a guest
May 24th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. #!/usr/local/bin/python3
  2.  
  3. import RPi.GPIO as GPIO
  4. import time
  5. import keyboard
  6. import curses
  7. import os
  8.  
  9. GPIO.setmode(GPIO.BOARD)
  10.  
  11. #define the pin that goes to the circuit
  12. pin_to_circuit = 7
  13.  
  14. start = 0
  15.  
  16.  
  17. button_delay = 0.2
  18.  
  19.  
  20. def rc_time (pin_to_circuit):
  21. count = 0
  22.  
  23. #Output on the pin for
  24. GPIO.setup(pin_to_circuit, GPIO.OUT)
  25. GPIO.output(pin_to_circuit, GPIO.LOW)
  26. time.sleep(0.1)
  27.  
  28. #Change the pin back to input
  29. GPIO.setup(pin_to_circuit, GPIO.IN)
  30.  
  31. #Count until the pin goes high
  32. while (GPIO.input(pin_to_circuit) == GPIO.LOW):
  33. count += 1
  34.  
  35. return count
  36.  
  37. #Catch when script is interrupted, cleanup correctly
  38. try:
  39. # Main loop
  40. while True:
  41. try:
  42. key = win.getkey()
  43. win.clear()
  44. win.addstr("Detected key:")
  45. win.addstr(str(key))
  46. print(key, os.linesep)
  47.  
  48. except Exception as e:
  49. # No input
  50. pass
  51.  
  52.  
  53. value = rc_time(pin_to_circuit)
  54.  
  55.  
  56. if value < 8000 and start == 1:
  57. print ("DAY LIGHT", value)
  58. else:
  59. print ("Night LIGHT", value)
  60.  
  61.  
  62. except KeyboardInterrupt:
  63. pass
  64. finally:
  65. GPIO.cleanup()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement