timber101

RainbowCreator

Apr 17th, 2021
255
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.51 KB | None
  1. #!/bin/python3
  2. # Colin's Rainbow creator!
  3. from sense_hat import SenseHat
  4.  
  5. sense = SenseHat()
  6. sense.clear()
  7.  
  8. R = [255,0,0]
  9. O = [255, 165,0]
  10. Y = [255,255,0]
  11. G = [0, 255,0]
  12. B = [0, 0,255 ] # Red , Green, Blue
  13. I = [25, 0, 255]
  14. V = [255, 0, 255]
  15. X = [0,0,0] # all off
  16. W = [255, 255, 255] # white
  17.  
  18. # sense.clear(X) # this is us testing
  19.  
  20. rainbow = [
  21. R, R, R, R, R, R, R, R,
  22. R, O, O, O, O, O, O, O,
  23. R, O, Y, Y, Y, Y, Y, Y,
  24. R, O, Y, G, G, G, G, G,
  25. R, O, Y, G, B, B, B, B,
  26. R, O, Y, G, B, I, I, I,
  27. R, O, Y, G, B, I, V, V,                                                                  
  28. R, O, Y, G, B, I, V, X
  29. ]
  30.  
  31. sunny = [
  32. Y, X, Y, X, X, Y, X, Y,
  33. X, O, Y, O, O, Y, O, X,
  34. Y, Y, O, Y, Y, O, Y, Y,
  35. X, O, Y, Y, Y, Y, O, X,
  36. X, O, Y, Y, Y, Y, O, X,
  37. Y, Y, O, Y, Y, O, O, Y,
  38. X, O, Y, O, O, Y, O, X,                                                                
  39. Y, X, Y, X, X, Y, X, Y
  40.  
  41.   ]
  42.  
  43. # my attempt at a snow man!
  44. cold = [
  45. X,X,X,W,W,X,X,X,
  46. X,X,W,W,W,W,X,X,
  47. X,X,X,W,W,X,X,X,
  48. X,X,W,W,W,W,X,X,
  49. X,W,W,W,W,W,W,X,
  50. X,X,W,W,W,W,X,X,
  51. X,X,X,W,W,X,X,X,
  52. X,X,X,X,X,X,X,X,
  53.  
  54. ]
  55.  
  56. #sense.set_pixels(rainbow) tester that the rainbow displayed
  57.  
  58. while True:  # forever loop
  59.   if sense.humidity > 80 and sense.temperature > 20:
  60.     sense.set_pixels(rainbow)
  61.   elif sense.humidity < 80 and sense.temperature > 20:
  62.     sense.set_pixels(sunny)
  63.   elif sense.temperature < 0:
  64.     sense.set_pixels(cold)
  65.   else:
  66.     sense.clear() # clears the pixels
  67.    
  68.  
  69.   #print(sense.temperature) # humidity and temperature
RAW Paste Data Copied