Advertisement
Guest User

Untitled

a guest
May 22nd, 2016
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1.  
  2. pi@raspberrypi:~ $ sudo python2 peter.py
  3. '4' is longer than 'HIGH'
  4. '4' is longer than 'HIGH'
  5. '4' is longer than 'HIGH'
  6. '4' is longer than 'HIGH'
  7. '4' is longer than 'HIGH'
  8. '4' is longer than 'HIGH'
  9. '4' is longer than 'HIGH'
  10. '4' is longer than 'HIGH'
  11. '4' is longer than 'HIGH'
  12. '4' is longer than 'HIGH'
  13. '4' is longer than 'HIGH'
  14. '4' is longer than 'HIGH'
  15. '4' is longer than 'HIGH'
  16. '4' is longer than 'HIGH'
  17. '4' is longer than 'HIGH'
  18. '4' is longer than 'HIGH'
  19. '4' is longer than 'HIGH'
  20. '4' is longer than 'HIGH'
  21. '4' is longer than 'HIGH'
  22. '4' is longer than 'HIGH'
  23. '4' is longer than 'HIGH'
  24. '4' is longer than 'HIGH'
  25. '4' is longer than 'HIGH'
  26. '4' is longer than 'HIGH'
  27. '4' is longer than 'HIGH'
  28. '4' is longer than 'HIGH'
  29. ^CTraceback (most recent call last):
  30. File "peter.py", line 17, in <module>
  31. time.sleep(0.1)
  32. KeyboardInterrupt
  33. pi@raspberrypi:~ $
  34.  
  35.  
  36.  
  37. import RPi.GPIO as GPIO
  38. import time
  39.  
  40. sensor = 4
  41. sensor2 = 17
  42. GPIO.setmode(GPIO.BCM)
  43. GPIO.setup(sensor, GPIO.IN, GPIO.PUD_DOWN)
  44. GPIO.setup(sensor2, GPIO.IN, GPIO.PUD_DOWN)
  45.  
  46. previous_state = False
  47. current_state = False
  48.  
  49. previous_state2 = False
  50. current_state2 = False
  51.  
  52. while True:
  53. time.sleep(0.1)
  54. previous_state = current_state
  55. previous_state2 = current_state2
  56. current_state = GPIO.input(sensor)
  57. current_state2 = GPIO.input(sensor2)
  58. if not(current_state and current_state2):
  59. new_state = "HIGH"
  60. new_state2 = "HIGH"
  61. print("'{0}' is longer than '{1}'".format(sensor, new_state))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement