Guest User

Time Project

a guest
May 22nd, 2017
106
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python
  2.  
  3. from datetime import datetime
  4. from sense_hat import SenseHat
  5. from time import sleep
  6.  
  7. sense = SenseHat()
  8. sense.set_rotation(180)
  9. sense.clear()
  10. sense.low_light = True
  11.  
  12. while True:
  13.  
  14. # Read the second, minute, and hour as a string, set to appropriately named variable.
  15. second = datetime.now().strftime('%S')
  16. minute = datetime.now().strftime('%M')
  17. hour = datetime.now().strftime('%H')
  18.  
  19. # Clears the hours (and everything else) once per 24 hours in order to start each day with a clean slate.
  20. if int(hour) == 23 and int(minute) == 59 and int(second) == 59:
  21. sense.clear()
  22.  
  23. # Interpret the string as an integer and light the appropriate LED every six seconds.
  24. # The "else" at the end of the seconds section sets all to 0 brightness at the 0 second each minute.
  25. ## if int(second) > 0 and int(second) < 7:
  26. ## sense.set_pixel(0,3,51,51,51)
  27. ##
  28. ## elif int(second) > 6 and int(second) < 13:
  29. ## sense.set_pixel(7,3,51,51,51)
  30. ##
  31. ## elif int(second) > 12 and int(second) < 19:
  32. ## sense.set_pixel(0,4,51,51,51)
  33. ##
  34. ## elif int(second) > 18 and int(second) < 25:
  35. ## sense.set_pixel(7,4,51,51,51)
  36. ##
  37. ## elif int(second) > 24 and int(second) < 31:
  38. ## sense.set_pixel(0,5,51,51,51)
  39. ##
  40. ## elif int(second) > 30 and int(second) < 37:
  41. ## sense.set_pixel(7,5,51,51,51)
  42. ##
  43. ## elif int(second) > 36 and int(second) < 43:
  44. ## sense.set_pixel(0,6,51,51,51)
  45. ##
  46. ## elif int(second) > 42 and int(second) < 49:
  47. ## sense.set_pixel(7,6,51,51,51)
  48. ##
  49. ## elif int(second) > 48 and int(second) < 55:
  50. ## sense.set_pixel(0,7,51,51,51)
  51. ##
  52. ## elif int(second) > 54 and int(second) < 61:
  53. ## sense.set_pixel(7,7,51,51,51)
  54. ## else:
  55. ## sense.set_pixel(0,3,0,0,0)
  56. ## sense.set_pixel(7,3,0,0,0)
  57. ## sense.set_pixel(0,4,0,0,0)
  58. ## sense.set_pixel(7,4,0,0,0)
  59. ## sense.set_pixel(0,5,0,0,0)
  60. ## sense.set_pixel(7,5,0,0,0)
  61. ## sense.set_pixel(0,6,0,0,0)
  62. ## sense.set_pixel(7,6,0,0,0)
  63. ## sense.set_pixel(0,7,0,0,0)
  64. ## sense.set_pixel(7,7,0,0,0)
  65.  
  66. if int(second) == 0 or int(second) == 10 or int(second) == 20 or int(second) == 30 or int(second) == 40 or int(second) == 50:
  67. sense.set_pixel(0,3,51,51,51)
  68.  
  69. elif int(second) == 1 or int(second) == 11 or int(second) == 21 or int(second) == 31 or int(second) == 41 or int(second) == 51:
  70. sense.set_pixel(7,3,51,51,51)
  71.  
  72. elif int(second) == 2 or int(second) == 12 or int(second) == 22 or int(second) == 32 or int(second) == 42 or int(second) == 52:
  73. sense.set_pixel(0,4,51,51,51)
  74.  
  75. elif int(second) == 3 or int(second) == 13 or int(second) == 23 or int(second) == 33 or int(second) == 43 or int(second) == 53:
  76. sense.set_pixel(7,4,51,51,51)
  77.  
  78. elif int(second) == 4 or int(second) == 14 or int(second) == 24 or int(second) == 34 or int(second) == 44 or int(second) == 54:
  79. sense.set_pixel(0,5,51,51,51)
  80.  
  81. elif int(second) == 5 or int(second) == 15 or int(second) == 25 or int(second) == 35 or int(second) == 45 or int(second) == 55:
  82. sense.set_pixel(7,5,51,51,51)
  83.  
  84. elif int(second) == 6 or int(second) == 16 or int(second) == 26 or int(second) == 36 or int(second) == 46 or int(second) == 56:
  85. sense.set_pixel(0,6,51,51,51)
  86.  
  87. elif int(second) == 7 or int(second) == 17 or int(second) == 27 or int(second) == 37 or int(second) == 47 or int(second) == 57:
  88. sense.set_pixel(7,6,51,51,51)
  89.  
  90. elif int(second) == 8 or int(second) == 18 or int(second) == 28 or int(second) == 38 or int(second) == 48 or int(second) == 58:
  91. sense.set_pixel(0,7,51,51,51)
  92.  
  93. # elif int(second) == 9 or int(second) == 19 or int(second) == 29 or int(second) == 39 or int(second) == 49:
  94. # sense.set_pixel(7,7,51,51,51)
  95. else:
  96. sense.set_pixel(0,3,0,0,0)
  97. sense.set_pixel(7,3,0,0,0)
  98. sense.set_pixel(0,4,0,0,0)
  99. sense.set_pixel(7,4,0,0,0)
  100. sense.set_pixel(0,5,0,0,0)
  101. sense.set_pixel(7,5,0,0,0)
  102. sense.set_pixel(0,6,0,0,0)
  103. sense.set_pixel(7,6,0,0,0)
  104. sense.set_pixel(0,7,0,0,0)
  105. sense.set_pixel(7,7,0,0,0)
  106.  
  107.  
  108. # Displays every other minute (2,4, etc) as a yellow LED in the 6x5 section (30 LEDs) from 1,3 to 6,7.
  109. # The "else" at the bottom of the minute section clears all yellow lights on the 0 minute.
  110. if int(minute) > 0 and int(minute) < 3:
  111. sense.set_pixel(1,3,255,255,0)
  112.  
  113. elif int(minute) > 2 and int(minute) < 5:
  114. sense.set_pixel(2,3,255,255,0)
  115.  
  116. elif int(minute) > 4 and int(minute) < 7:
  117. sense.set_pixel(3,3,255,255,0)
  118.  
  119. elif int(minute) > 6 and int(minute) < 9:
  120. sense.set_pixel(4,3,255,255,0)
  121.  
  122. elif int(minute) > 8 and int(minute) < 11:
  123. sense.set_pixel(5,3,255,255,0)
  124.  
  125. elif int(minute) > 10 and int(minute) < 13:
  126. sense.set_pixel(6,3,255,255,0)
  127.  
  128. elif int(minute) > 12 and int(minute) < 15:
  129. sense.set_pixel(1,4,255,255,0)
  130.  
  131. elif int(minute) > 14 and int(minute) < 17:
  132. sense.set_pixel(2,4,255,255,0)
  133.  
  134. elif int(minute) > 16 and int(minute) < 19:
  135. sense.set_pixel(3,4,255,255,0)
  136.  
  137. elif int(minute) > 18 and int(minute) < 21:
  138. sense.set_pixel(4,4,255,255,0)
  139.  
  140. elif int(minute) > 20 and int(minute) < 23:
  141. sense.set_pixel(5,4,255,255,0)
  142.  
  143. elif int(minute) > 22 and int(minute) < 25:
  144. sense.set_pixel(6,4,255,255,0)
  145.  
  146. elif int(minute) > 24 and int(minute) < 27:
  147. sense.set_pixel(1,5,255,255,0)
  148.  
  149. elif int(minute) > 26 and int(minute) < 29:
  150. sense.set_pixel(2,5,255,255,0)
  151.  
  152. elif int(minute) > 28 and int(minute) < 31:
  153. sense.set_pixel(3,5,255,255,0)
  154.  
  155. elif int(minute) > 30 and int(minute) < 33:
  156. sense.set_pixel(4,5,255,255,0)
  157.  
  158. elif int(minute) > 32 and int(minute) < 35:
  159. sense.set_pixel(5,5,255,255,0)
  160.  
  161. elif int(minute) > 34 and int(minute) < 37:
  162. sense.set_pixel(6,5,255,255,0)
  163.  
  164. elif int(minute) > 36 and int(minute) < 39:
  165. sense.set_pixel(1,6,255,255,0)
  166.  
  167. elif int(minute) > 38 and int(minute) < 41:
  168. sense.set_pixel(2,6,255,255,0)
  169.  
  170. elif int(minute) > 40 and int(minute) < 43:
  171. sense.set_pixel(3,6,255,255,0)
  172.  
  173. elif int(minute) > 42 and int(minute) < 45:
  174. sense.set_pixel(4,6,255,255,0)
  175.  
  176. elif int(minute) > 44 and int(minute) < 47:
  177. sense.set_pixel(5,6,255,255,0)
  178.  
  179. elif int(minute) > 46 and int(minute) < 49:
  180. sense.set_pixel(6,6,255,255,0)
  181.  
  182. elif int(minute) > 48 and int(minute) < 51:
  183. sense.set_pixel(1,7,255,255,0)
  184.  
  185. elif int(minute) > 50 and int(minute) < 53:
  186. sense.set_pixel(2,7,255,255,0)
  187.  
  188. elif int(minute) > 52 and int(minute) < 55:
  189. sense.set_pixel(3,7,255,255,0)
  190.  
  191. elif int(minute) > 54 and int(minute) < 57:
  192. sense.set_pixel(4,7,255,255,0)
  193.  
  194. elif int(minute) > 56 and int(minute) < 59:
  195. sense.set_pixel(5,7,255,255,0)
  196.  
  197. elif int(minute) > 58 and int(minute) < 61:
  198. sense.set_pixel(6,7,255,255,0)
  199.  
  200. else:
  201. sense.set_pixel(1,3,0,0,0)
  202. sense.set_pixel(2,3,0,0,0)
  203. sense.set_pixel(3,3,0,0,0)
  204. sense.set_pixel(4,3,0,0,0)
  205. sense.set_pixel(5,3,0,0,0)
  206. sense.set_pixel(6,3,0,0,0)
  207. sense.set_pixel(1,4,0,0,0)
  208. sense.set_pixel(2,4,0,0,0)
  209. sense.set_pixel(3,4,0,0,0)
  210. sense.set_pixel(4,4,0,0,0)
  211. sense.set_pixel(5,4,0,0,0)
  212. sense.set_pixel(6,4,0,0,0)
  213. sense.set_pixel(1,5,0,0,0)
  214. sense.set_pixel(2,5,0,0,0)
  215. sense.set_pixel(3,5,0,0,0)
  216. sense.set_pixel(4,5,0,0,0)
  217. sense.set_pixel(5,5,0,0,0)
  218. sense.set_pixel(6,5,0,0,0)
  219. sense.set_pixel(1,6,0,0,0)
  220. sense.set_pixel(2,6,0,0,0)
  221. sense.set_pixel(3,6,0,0,0)
  222. sense.set_pixel(4,6,0,0,0)
  223. sense.set_pixel(5,6,0,0,0)
  224. sense.set_pixel(6,6,0,0,0)
  225. sense.set_pixel(1,7,0,0,0)
  226. sense.set_pixel(2,7,0,0,0)
  227. sense.set_pixel(3,7,0,0,0)
  228. sense.set_pixel(4,7,0,0,0)
  229. sense.set_pixel(5,7,0,0,0)
  230. sense.set_pixel(6,7,0,0,0)
  231.  
  232. # Displays a color-coded LED for every hour using rows 0,1, and 2. 8x3=24 hours, 1-8AM, 9-4PM, and 5-12PM.
  233. if int(hour) == 0:
  234. sense.set_pixel(0,0,0,0,0)
  235.  
  236. elif int(hour) == 1:
  237. sense.set_pixel(0,0,0,0,102)
  238.  
  239. elif int(hour) == 2:
  240. sense.set_pixel(1,0,0,0,153)
  241.  
  242. elif int(hour) == 3:
  243. sense.set_pixel(2,0,0,0,204)
  244.  
  245. elif int(hour) == 4:
  246. sense.set_pixel(3,0,0,0,255)
  247.  
  248. elif int(hour) == 5:
  249. sense.set_pixel(4,0,0,128,255)
  250.  
  251. elif int(hour) == 6:
  252. sense.set_pixel(5,0,0,255,255)
  253.  
  254. elif int(hour) == 7:
  255. sense.set_pixel(6,0,0,255,128)
  256.  
  257. elif int(hour) == 8:
  258. sense.set_pixel(7,0,0,204,0)
  259.  
  260. elif int(hour) == 9:
  261. sense.set_pixel(0,1,0,255,0)
  262.  
  263. elif int(hour) == 10:
  264. sense.set_pixel(1,1,128,255,0)
  265.  
  266. elif int(hour) == 11:
  267. sense.set_pixel(2,1,153,255,51)
  268.  
  269. elif int(hour) == 12:
  270. sense.set_pixel(3,1,255,255,51)
  271.  
  272. elif int(hour) == 13:
  273. sense.set_pixel(4,1,55,128,0)
  274.  
  275. elif int(hour) == 14:
  276. sense.set_pixel(5,1,255,51,51)
  277.  
  278. elif int(hour) == 15:
  279. sense.set_pixel(6,1,255,0,0)
  280.  
  281. elif int(hour) == 16:
  282. sense.set_pixel(7,1,204,0,0)
  283.  
  284. elif int(hour) == 17:
  285. sense.set_pixel(0,2,153,0,0)
  286.  
  287. elif int(hour) == 18:
  288. sense.set_pixel(1,2,102,0,0)
  289.  
  290. elif int(hour) == 19:
  291. sense.set_pixel(2,2,51,0,0)
  292.  
  293. elif int(hour) == 20:
  294. sense.set_pixel(3,2,0,0,51)
  295.  
  296. elif int(hour) == 21:
  297. sense.set_pixel(4,2,0,0,102)
  298.  
  299. elif int(hour) == 22:
  300. sense.set_pixel(5,2,0,0,153)
  301.  
  302. elif int(hour) == 23:
  303. sense.set_pixel(6,2,0,0,204)
  304.  
  305. elif int(hour) == 24:
  306. sense.set_pixel(7,2,0,0,255)
  307. sleep(0.5)
RAW Paste Data