• API
• FAQ
• Tools
• Archive
daily pastebin goal
16%
SHARE
TWEET

# SenseHat Sunrise

sweenig Aug 5th, 2016 755 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. from sense_hat import SenseHat
2. import time
3.
4. s = SenseHat()
5. #s.low_light = True
6.
7. midnight = [25, 25, 112] #possible future color during night time
8. targetcolor = [253, 94, 83] #this is the color of the sunrise. I picked one. Modify as needed [R,G,B]
9. duration = 6400 #this is the total amount of time that the sun should take to rise, there are 64 LEDs and they each cycle through from 1 to 100, so 6400 gets you 1 second per LED. If you want a faster sunrise, lower this number
10. dayduration = 900 #this is the total amount of time that the sun should stay risen (900s = 15min)
11. def drawsun(brightness): #function to draw all 64 pixels at a specified percentage of the final color.
12.         red = targetcolor[0] * brightness / 100 #calculate the R value for the given progress between 0 and the target R value.
13.         green = targetcolor[1] * brightness / 100 #calculate the G value for the given progress between 0 and the target G value.
14.         blue = int(targetcolor[2] * brightness / 100) #calculate the B value for the given progress between 0 and the target B value.
15.         for y in range(8): #cycle through every row
16.                 for x in range(8): #cycle through every column
17.                         s.set_pixel(x,y,red,green,blue) #set the pixel
18.                         time.sleep(duration/6400) #wait before moving on
19. try:
20.         print "Sun rising..."
21.         for a in range(1,101): #cycle through the brightness levels from 1 to 100
22.                 drawsun(a)
23.                 print "Brightness: ", str(a)
24.         print "Sun up."
25.         time.sleep(dayduration) #let the sun shine in!
26.         print "Sun setting..."
27.         for b in range(99,-1,-1): #cycle through the brightness levels back down to 0
28.                 drawsun(b)
29. except:
30.         print("terminated manually")
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top