Guest User

Untitled

a guest
Nov 20th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. import RPi.GPIO as GPIO
  4. import time
  5. import random
  6.  
  7.  
  8. GPIO_RED = 10
  9. GPIO_GREEN = 9
  10. GPIO_BLUE = 11
  11. GPIOS = (GPIO_RED, GPIO_GREEN, GPIO_BLUE)
  12.  
  13.  
  14. GPIO.setmode(GPIO.BCM)
  15.  
  16. for gpio in GPIOS:
  17. GPIO.setup(gpio, GPIO.OUT)
  18.  
  19.  
  20. def rand():
  21. return random.choice((False, True))
  22.  
  23.  
  24. def setcolor(r, g, b):
  25. GPIO.output(GPIO_RED, r)
  26. GPIO.output(GPIO_GREEN, g)
  27. GPIO.output(GPIO_BLUE, b)
  28.  
  29.  
  30. if __name__ == '__main__':
  31. try:
  32. while True:
  33. setcolor(rand(), rand(), rand())
  34. time.sleep(random.random())
  35. except KeyboardInterrupt:
  36. GPIO.cleanup()
Add Comment
Please, Sign In to add comment