Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- from datetime import datetime
- from sense_hat import SenseHat
- from time import sleep
- sense = SenseHat()
- sense.set_rotation(180)
- sense.clear()
- sense.low_light = True
- while True:
- # Read the second, minute, and hour as a string, set to appropriately named variable.
- second = datetime.now().strftime('%S')
- minute = datetime.now().strftime('%M')
- hour = datetime.now().strftime('%H')
- # Clears the hours (and everything else) once per 24 hours in order to start each day with a clean slate.
- if int(hour) == 23 and int(minute) == 59 and int(second) == 59:
- sense.clear()
- # Interpret the string as an integer and light the appropriate LED every six seconds.
- # The "else" at the end of the seconds section sets all to 0 brightness at the 0 second each minute.
- ## if int(second) > 0 and int(second) < 7:
- ## sense.set_pixel(0,3,51,51,51)
- ##
- ## elif int(second) > 6 and int(second) < 13:
- ## sense.set_pixel(7,3,51,51,51)
- ##
- ## elif int(second) > 12 and int(second) < 19:
- ## sense.set_pixel(0,4,51,51,51)
- ##
- ## elif int(second) > 18 and int(second) < 25:
- ## sense.set_pixel(7,4,51,51,51)
- ##
- ## elif int(second) > 24 and int(second) < 31:
- ## sense.set_pixel(0,5,51,51,51)
- ##
- ## elif int(second) > 30 and int(second) < 37:
- ## sense.set_pixel(7,5,51,51,51)
- ##
- ## elif int(second) > 36 and int(second) < 43:
- ## sense.set_pixel(0,6,51,51,51)
- ##
- ## elif int(second) > 42 and int(second) < 49:
- ## sense.set_pixel(7,6,51,51,51)
- ##
- ## elif int(second) > 48 and int(second) < 55:
- ## sense.set_pixel(0,7,51,51,51)
- ##
- ## elif int(second) > 54 and int(second) < 61:
- ## sense.set_pixel(7,7,51,51,51)
- ## else:
- ## sense.set_pixel(0,3,0,0,0)
- ## sense.set_pixel(7,3,0,0,0)
- ## sense.set_pixel(0,4,0,0,0)
- ## sense.set_pixel(7,4,0,0,0)
- ## sense.set_pixel(0,5,0,0,0)
- ## sense.set_pixel(7,5,0,0,0)
- ## sense.set_pixel(0,6,0,0,0)
- ## sense.set_pixel(7,6,0,0,0)
- ## sense.set_pixel(0,7,0,0,0)
- ## sense.set_pixel(7,7,0,0,0)
- if int(second) == 0 or int(second) == 10 or int(second) == 20 or int(second) == 30 or int(second) == 40 or int(second) == 50:
- sense.set_pixel(0,3,51,51,51)
- elif int(second) == 1 or int(second) == 11 or int(second) == 21 or int(second) == 31 or int(second) == 41 or int(second) == 51:
- sense.set_pixel(7,3,51,51,51)
- elif int(second) == 2 or int(second) == 12 or int(second) == 22 or int(second) == 32 or int(second) == 42 or int(second) == 52:
- sense.set_pixel(0,4,51,51,51)
- elif int(second) == 3 or int(second) == 13 or int(second) == 23 or int(second) == 33 or int(second) == 43 or int(second) == 53:
- sense.set_pixel(7,4,51,51,51)
- elif int(second) == 4 or int(second) == 14 or int(second) == 24 or int(second) == 34 or int(second) == 44 or int(second) == 54:
- sense.set_pixel(0,5,51,51,51)
- elif int(second) == 5 or int(second) == 15 or int(second) == 25 or int(second) == 35 or int(second) == 45 or int(second) == 55:
- sense.set_pixel(7,5,51,51,51)
- elif int(second) == 6 or int(second) == 16 or int(second) == 26 or int(second) == 36 or int(second) == 46 or int(second) == 56:
- sense.set_pixel(0,6,51,51,51)
- elif int(second) == 7 or int(second) == 17 or int(second) == 27 or int(second) == 37 or int(second) == 47 or int(second) == 57:
- sense.set_pixel(7,6,51,51,51)
- elif int(second) == 8 or int(second) == 18 or int(second) == 28 or int(second) == 38 or int(second) == 48 or int(second) == 58:
- sense.set_pixel(0,7,51,51,51)
- # elif int(second) == 9 or int(second) == 19 or int(second) == 29 or int(second) == 39 or int(second) == 49:
- # sense.set_pixel(7,7,51,51,51)
- else:
- sense.set_pixel(0,3,0,0,0)
- sense.set_pixel(7,3,0,0,0)
- sense.set_pixel(0,4,0,0,0)
- sense.set_pixel(7,4,0,0,0)
- sense.set_pixel(0,5,0,0,0)
- sense.set_pixel(7,5,0,0,0)
- sense.set_pixel(0,6,0,0,0)
- sense.set_pixel(7,6,0,0,0)
- sense.set_pixel(0,7,0,0,0)
- sense.set_pixel(7,7,0,0,0)
- # Displays every other minute (2,4, etc) as a yellow LED in the 6x5 section (30 LEDs) from 1,3 to 6,7.
- # The "else" at the bottom of the minute section clears all yellow lights on the 0 minute.
- if int(minute) > 0 and int(minute) < 3:
- sense.set_pixel(1,3,255,255,0)
- elif int(minute) > 2 and int(minute) < 5:
- sense.set_pixel(2,3,255,255,0)
- elif int(minute) > 4 and int(minute) < 7:
- sense.set_pixel(3,3,255,255,0)
- elif int(minute) > 6 and int(minute) < 9:
- sense.set_pixel(4,3,255,255,0)
- elif int(minute) > 8 and int(minute) < 11:
- sense.set_pixel(5,3,255,255,0)
- elif int(minute) > 10 and int(minute) < 13:
- sense.set_pixel(6,3,255,255,0)
- elif int(minute) > 12 and int(minute) < 15:
- sense.set_pixel(1,4,255,255,0)
- elif int(minute) > 14 and int(minute) < 17:
- sense.set_pixel(2,4,255,255,0)
- elif int(minute) > 16 and int(minute) < 19:
- sense.set_pixel(3,4,255,255,0)
- elif int(minute) > 18 and int(minute) < 21:
- sense.set_pixel(4,4,255,255,0)
- elif int(minute) > 20 and int(minute) < 23:
- sense.set_pixel(5,4,255,255,0)
- elif int(minute) > 22 and int(minute) < 25:
- sense.set_pixel(6,4,255,255,0)
- elif int(minute) > 24 and int(minute) < 27:
- sense.set_pixel(1,5,255,255,0)
- elif int(minute) > 26 and int(minute) < 29:
- sense.set_pixel(2,5,255,255,0)
- elif int(minute) > 28 and int(minute) < 31:
- sense.set_pixel(3,5,255,255,0)
- elif int(minute) > 30 and int(minute) < 33:
- sense.set_pixel(4,5,255,255,0)
- elif int(minute) > 32 and int(minute) < 35:
- sense.set_pixel(5,5,255,255,0)
- elif int(minute) > 34 and int(minute) < 37:
- sense.set_pixel(6,5,255,255,0)
- elif int(minute) > 36 and int(minute) < 39:
- sense.set_pixel(1,6,255,255,0)
- elif int(minute) > 38 and int(minute) < 41:
- sense.set_pixel(2,6,255,255,0)
- elif int(minute) > 40 and int(minute) < 43:
- sense.set_pixel(3,6,255,255,0)
- elif int(minute) > 42 and int(minute) < 45:
- sense.set_pixel(4,6,255,255,0)
- elif int(minute) > 44 and int(minute) < 47:
- sense.set_pixel(5,6,255,255,0)
- elif int(minute) > 46 and int(minute) < 49:
- sense.set_pixel(6,6,255,255,0)
- elif int(minute) > 48 and int(minute) < 51:
- sense.set_pixel(1,7,255,255,0)
- elif int(minute) > 50 and int(minute) < 53:
- sense.set_pixel(2,7,255,255,0)
- elif int(minute) > 52 and int(minute) < 55:
- sense.set_pixel(3,7,255,255,0)
- elif int(minute) > 54 and int(minute) < 57:
- sense.set_pixel(4,7,255,255,0)
- elif int(minute) > 56 and int(minute) < 59:
- sense.set_pixel(5,7,255,255,0)
- elif int(minute) > 58 and int(minute) < 61:
- sense.set_pixel(6,7,255,255,0)
- else:
- sense.set_pixel(1,3,0,0,0)
- sense.set_pixel(2,3,0,0,0)
- sense.set_pixel(3,3,0,0,0)
- sense.set_pixel(4,3,0,0,0)
- sense.set_pixel(5,3,0,0,0)
- sense.set_pixel(6,3,0,0,0)
- sense.set_pixel(1,4,0,0,0)
- sense.set_pixel(2,4,0,0,0)
- sense.set_pixel(3,4,0,0,0)
- sense.set_pixel(4,4,0,0,0)
- sense.set_pixel(5,4,0,0,0)
- sense.set_pixel(6,4,0,0,0)
- sense.set_pixel(1,5,0,0,0)
- sense.set_pixel(2,5,0,0,0)
- sense.set_pixel(3,5,0,0,0)
- sense.set_pixel(4,5,0,0,0)
- sense.set_pixel(5,5,0,0,0)
- sense.set_pixel(6,5,0,0,0)
- sense.set_pixel(1,6,0,0,0)
- sense.set_pixel(2,6,0,0,0)
- sense.set_pixel(3,6,0,0,0)
- sense.set_pixel(4,6,0,0,0)
- sense.set_pixel(5,6,0,0,0)
- sense.set_pixel(6,6,0,0,0)
- sense.set_pixel(1,7,0,0,0)
- sense.set_pixel(2,7,0,0,0)
- sense.set_pixel(3,7,0,0,0)
- sense.set_pixel(4,7,0,0,0)
- sense.set_pixel(5,7,0,0,0)
- sense.set_pixel(6,7,0,0,0)
- # Displays a color-coded LED for every hour using rows 0,1, and 2. 8x3=24 hours, 1-8AM, 9-4PM, and 5-12PM.
- if int(hour) == 0:
- sense.set_pixel(0,0,0,0,0)
- elif int(hour) == 1:
- sense.set_pixel(0,0,0,0,102)
- elif int(hour) == 2:
- sense.set_pixel(1,0,0,0,153)
- elif int(hour) == 3:
- sense.set_pixel(2,0,0,0,204)
- elif int(hour) == 4:
- sense.set_pixel(3,0,0,0,255)
- elif int(hour) == 5:
- sense.set_pixel(4,0,0,128,255)
- elif int(hour) == 6:
- sense.set_pixel(5,0,0,255,255)
- elif int(hour) == 7:
- sense.set_pixel(6,0,0,255,128)
- elif int(hour) == 8:
- sense.set_pixel(7,0,0,204,0)
- elif int(hour) == 9:
- sense.set_pixel(0,1,0,255,0)
- elif int(hour) == 10:
- sense.set_pixel(1,1,128,255,0)
- elif int(hour) == 11:
- sense.set_pixel(2,1,153,255,51)
- elif int(hour) == 12:
- sense.set_pixel(3,1,255,255,51)
- elif int(hour) == 13:
- sense.set_pixel(4,1,55,128,0)
- elif int(hour) == 14:
- sense.set_pixel(5,1,255,51,51)
- elif int(hour) == 15:
- sense.set_pixel(6,1,255,0,0)
- elif int(hour) == 16:
- sense.set_pixel(7,1,204,0,0)
- elif int(hour) == 17:
- sense.set_pixel(0,2,153,0,0)
- elif int(hour) == 18:
- sense.set_pixel(1,2,102,0,0)
- elif int(hour) == 19:
- sense.set_pixel(2,2,51,0,0)
- elif int(hour) == 20:
- sense.set_pixel(3,2,0,0,51)
- elif int(hour) == 21:
- sense.set_pixel(4,2,0,0,102)
- elif int(hour) == 22:
- sense.set_pixel(5,2,0,0,153)
- elif int(hour) == 23:
- sense.set_pixel(6,2,0,0,204)
- elif int(hour) == 24:
- sense.set_pixel(7,2,0,0,255)
- sleep(0.5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement