1
1
# Grayscale library demo
2
+ # https://github.com/Timendus/thumby-grayscale
2
3
#
3
- # Shows four different screens, then reboots. Cycle through the screens by
4
- # pressing A (rightmost button), go to calibration screen by pressing B (lefmost
5
- # button). When on calibration screen, up and down change the grayscale timing
6
- # in large increments, left and right in small increments, A or B confirms.
4
+ # Shows six different screens, then reboots. Cycle through the screens by
5
+ # pressing A or B.
7
6
8
7
# Fix import path so it finds the grayscale library
9
8
import sys
10
9
sys .path .insert (0 , "/" .join (__file__ .split ("/" )[0 :- 1 ]))
11
10
12
- # Do imports
13
- import thumby
14
- from framebuf import FrameBuffer , MONO_VLSB
15
- from time import ticks_ms , sleep_us , sleep_ms
11
+ # Import dependencies
12
+ from thumbyButton import actionPressed
13
+ from machine import reset
14
+ from time import sleep_ms
15
+ from utime import ticks_us , sleep_us , ticks_diff
16
16
import grayscale
17
17
18
18
# Initialization
19
19
20
- thumby .audio .stop ()
21
- thumby .display .setFPS (0 )
22
- thumby .display .brightness (28 )
23
20
gs = grayscale .Grayscale ()
24
21
25
- # Helper functions
26
-
27
- def configureGrayscale ():
28
- global gs
29
- grayscale .Calibration (gs ).start ()
30
- gs .stop ()
31
- gs .saveConfig ()
32
- gs = grayscale .Grayscale ()
22
+ # Helper function
33
23
34
24
def waitKey ():
35
- while thumby .buttonA .pressed () or thumby .buttonB .pressed ():
36
- pass
37
- while True :
38
- if thumby .buttonA .pressed ():
39
- return
40
- if thumby .buttonB .pressed ():
41
- return configureGrayscale ()
42
-
43
- # Drawing primitives demo
44
-
45
- gs .fill (gs .BLACK )
46
- gs .drawFilledRectangle (16 , 9 , 40 , 21 , gs .WHITE )
47
- gs .drawText ("Hello" , 18 , 11 , gs .LIGHTGRAY )
48
- gs .drawText ("world!" , 18 , 19 , gs .DARKGRAY )
25
+ while actionPressed (): pass
26
+ while not actionPressed (): pass
27
+ while actionPressed (): pass
28
+
29
+ # Directly writing to the buffers
30
+
31
+ for s in range (4 ):
32
+ if s & 1 :
33
+ m1 = 0xff
34
+ else :
35
+ m1 = 0
36
+ if s & 2 :
37
+ m2 = 0xff
38
+ else :
39
+ m2 = 0
40
+ sx = s * 18
41
+ for y in range (5 ):
42
+ sy = y * 72
43
+ for x in range (18 ):
44
+ gs .buffer1 [sy + sx + x ] = m1
45
+ gs .buffer2 [sy + sx + x ] = m2
46
+ gs .show ()
49
47
waitKey ()
50
48
51
- # Bouncing cat demo
49
+ # Drawing primitives
50
+
51
+ gs .drawFilledRectangle (0 , 0 , 72 , 40 , gs .WHITE )
52
+ gs .drawFilledRectangle (0 , 0 , 62 , 30 , gs .LIGHTGRAY )
53
+ gs .drawFilledRectangle (0 , 0 , 52 , 20 , gs .DARKGRAY )
54
+ gs .drawFilledRectangle (0 , 0 , 42 , 10 , gs .BLACK )
55
+ gs .drawText ("Hello" , 2 , 31 , gs .LIGHTGRAY )
56
+ gs .drawText ("world!" , 37 , 31 , gs .DARKGRAY )
57
+ gs .update ()
58
+ waitKey ()
52
59
53
- while thumby .buttonA .pressed () or thumby .buttonB .pressed ():
54
- pass
60
+ # Sprites as full screen images
61
+
62
+ girlSprite = grayscale .Sprite (72 , 40 , bytearray ([
63
+ 128 ,4 ,160 ,8 ,130 ,32 ,8 ,162 ,0 ,40 ,130 ,8 ,160 ,10 ,64 ,39 ,53 ,187 ,234 ,149 ,106 ,181 ,214 ,253 ,135 ,1 ,81 ,44 ,210 ,40 ,74 ,180 ,192 ,40 ,129 ,1 ,135 ,207 ,191 ,254 ,232 ,218 ,144 ,96 ,1 ,131 ,7 ,13 ,30 ,59 ,237 ,246 ,217 ,38 ,219 ,171 ,94 ,173 ,106 ,225 ,148 ,64 ,8 ,130 ,32 ,8 ,162 ,0 ,40 ,2 ,144 ,4 ,
64
+ 0 ,84 ,0 ,18 ,64 ,136 ,2 ,168 ,2 ,80 ,10 ,64 ,10 ,160 ,5 ,168 ,1 ,85 ,135 ,30 ,189 ,122 ,127 ,103 ,37 ,134 ,17 ,0 ,133 ,64 ,3 ,1 ,11 ,141 ,6 ,181 ,20 ,31 ,15 ,87 ,79 ,215 ,255 ,255 ,216 ,32 ,193 ,160 ,112 ,208 ,248 ,243 ,239 ,159 ,124 ,235 ,212 ,187 ,69 ,186 ,215 ,94 ,248 ,200 ,130 ,32 ,10 ,160 ,5 ,80 ,4 ,0 ,
65
+ 0 ,149 ,32 ,133 ,80 ,8 ,66 ,40 ,2 ,169 ,4 ,81 ,8 ,162 ,8 ,146 ,36 ,129 ,40 ,130 ,104 ,213 ,74 ,136 ,224 ,224 ,192 ,68 ,198 ,201 ,134 ,192 ,137 ,64 ,2 ,224 ,16 ,232 ,182 ,125 ,255 ,255 ,255 ,255 ,107 ,206 ,63 ,191 ,222 ,127 ,71 ,241 ,215 ,127 ,244 ,0 ,3 ,15 ,61 ,126 ,233 ,246 ,219 ,255 ,16 ,74 ,0 ,74 ,32 ,5 ,168 ,1 ,
66
+ 2 ,80 ,10 ,160 ,10 ,81 ,4 ,145 ,34 ,136 ,33 ,74 ,208 ,138 ,32 ,198 ,122 ,212 ,173 ,116 ,170 ,5 ,20 ,143 ,16 ,167 ,1 ,177 ,87 ,62 ,99 ,114 ,48 ,125 ,180 ,189 ,254 ,223 ,255 ,255 ,127 ,63 ,187 ,254 ,255 ,232 ,167 ,253 ,87 ,217 ,255 ,255 ,255 ,200 ,190 ,232 ,0 ,162 ,0 ,81 ,4 ,147 ,35 ,136 ,37 ,144 ,69 ,16 ,37 ,128 ,42 ,64 ,
67
+ 160 ,21 ,64 ,20 ,66 ,17 ,136 ,34 ,200 ,146 ,196 ,145 ,195 ,215 ,168 ,127 ,138 ,117 ,10 ,37 ,138 ,20 ,128 ,197 ,195 ,32 ,88 ,151 ,33 ,212 ,201 ,226 ,200 ,245 ,234 ,226 ,255 ,254 ,167 ,73 ,0 ,5 ,2 ,195 ,11 ,243 ,2 ,225 ,95 ,223 ,191 ,255 ,127 ,255 ,250 ,255 ,122 ,136 ,66 ,41 ,4 ,80 ,10 ,32 ,138 ,32 ,74 ,17 ,68 ,18 ,64 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 ,106 ,179 ,247 ,94 ,232 ,149 ,73 ,107 ,19 ,245 ,86 ,236 ,233 ,100 ,157 ,139 ,140 ,
79
+ 0 ,64 ,64 ,64 ,0 ,128 ,0 ,0 ,88 ,40 ,192 ,1 ,105 ,50 ,32 ,24 ,31 ,254 ,223 ,222 ,188 ,75 ,187 ,23 ,247 ,9 ,231 ,193 ,15 ,129 ,6 ,0 ,130 ,0 ,64 ,144 ,64 ,136 ,160 ,72 ,176 ,64 ,160 ,64 ,160 ,248 ,232 ,112 ,32 ,8 ,0 ,8 ,0 ,0 ,0 ,1 ,23 ,14 ,60 ,48 ,32 ,10 ,40 ,145 ,1 ,3 ,5 ,18 ,3 ,14 ,63 ,91 ,
80
+ 16 ,48 ,52 ,36 ,100 ,227 ,64 ,64 ,128 ,193 ,35 ,1 ,42 ,33 ,112 ,108 ,96 ,222 ,248 ,242 ,204 ,187 ,73 ,255 ,251 ,223 ,227 ,252 ,91 ,247 ,94 ,121 ,252 ,252 ,191 ,254 ,189 ,252 ,223 ,126 ,249 ,253 ,250 ,252 ,255 ,253 ,122 ,244 ,57 ,222 ,42 ,156 ,170 ,78 ,24 ,165 ,74 ,16 ,68 ,16 ,192 ,16 ,161 ,71 ,24 ,250 ,232 ,128 ,104 ,128 ,4 ,184 ,
81
+ 201 ,130 ,199 ,100 ,67 ,239 ,1 ,150 ,241 ,112 ,114 ,124 ,249 ,182 ,8 ,85 ,251 ,239 ,191 ,253 ,251 ,223 ,253 ,239 ,191 ,250 ,231 ,155 ,79 ,192 ,211 ,253 ,239 ,125 ,255 ,127 ,221 ,127 ,175 ,127 ,255 ,95 ,255 ,111 ,255 ,124 ,247 ,188 ,235 ,188 ,234 ,77 ,176 ,74 ,181 ,66 ,121 ,68 ,169 ,66 ,244 ,191 ,74 ,150 ,45 ,127 ,191 ,255 ,236 ,128 ,253 ,123
82
+ ]), bytearray ([
83
+ 64 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,40 ,24 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33 ,213 ,99 ,85 ,177 ,231 ,90 ,181 ,239 ,187 ,239 ,63 ,239 ,94 ,184 ,231 ,5 ,23 ,127 ,151 ,127 ,251 ,71 ,
87
+ 54 ,125 ,56 ,153 ,128 ,16 ,254 ,105 ,14 ,143 ,141 ,131 ,6 ,73 ,247 ,170 ,4 ,16 ,64 ,2 ,4 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,128 ,0 ,128 ,32 ,128 ,80 ,128 ,0 ,160 ,0 ,144 ,0 ,131 ,8 ,67 ,20 ,67 ,21 ,178 ,79 ,181 ,74 ,189 ,134 ,187 ,86 ,189 ,11 ,64 ,181 ,105 ,210 ,128 ,64 ,0 ,19 ,127 ,2 ,132
88
+ ]))
89
+
90
+ gs .drawSprite (girlSprite )
91
+ gs .update ()
92
+ waitKey ()
93
+
94
+ gs .drawSprite (parrotSprite )
95
+ gs .update ()
96
+ waitKey ()
97
+
98
+ # Cat animation using a sprite
55
99
56
100
cat = grayscale .Sprite (
57
101
12 , 9 , # Dimensions
58
- bytearray ([ # Layer 1 data
59
- 175 ,7 ,169 ,254 ,237 ,255 ,191 ,157 ,190 ,233 ,255 ,175 ,
60
- 1 ,1 ,0 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1
61
- ]),
62
102
bytearray ([ # Layer 2 data
63
103
255 ,255 ,87 ,7 ,3 ,3 ,3 ,67 ,3 ,7 ,7 ,255 ,
64
104
1 ,1 ,1 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,1 ,1
65
105
]),
106
+ bytearray ([ # Layer 1 data
107
+ 175 ,7 ,169 ,254 ,237 ,255 ,191 ,157 ,190 ,233 ,255 ,175 ,
108
+ 1 ,1 ,0 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1
109
+ ]),
66
110
30 , 15 # Position
67
111
)
68
112
@@ -76,50 +120,58 @@ def waitKey():
76
120
dx = - 1 * dx
77
121
if cat .y == 0 or cat .y == 31 :
78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,17 ,0 ,133 ,64 ,3 ,1 ,11 ,141 ,6 ,181 ,20 ,31 ,15 ,87 ,79 ,215 ,255 ,255 ,216 ,32 ,193 ,160 ,112 ,208 ,248 ,243 ,239 ,159 ,124 ,235 ,212 ,187 ,69 ,186 ,215 ,94 ,248 ,200 ,130 ,32 ,10 ,160 ,5 ,80 ,4 ,0 ,
98
- 0 ,149 ,32 ,133 ,80 ,8 ,66 ,40 ,2 ,169 ,4 ,81 ,8 ,162 ,8 ,146 ,36 ,129 ,40 ,130 ,104 ,213 ,74 ,136 ,224 ,224 ,192 ,68 ,198 ,201 ,134 ,192 ,137 ,64 ,2 ,224 ,16 ,232 ,182 ,125 ,255 ,255 ,255 ,255 ,107 ,206 ,63 ,191 ,222 ,127 ,71 ,241 ,215 ,127 ,244 ,0 ,3 ,15 ,61 ,126 ,233 ,246 ,219 ,255 ,16 ,74 ,0 ,74 ,32 ,5 ,168 ,1 ,
99
- 2 ,80 ,10 ,160 ,10 ,81 ,4 ,145 ,34 ,136 ,33 ,74 ,208 ,138 ,32 ,198 ,122 ,212 ,173 ,116 ,170 ,5 ,20 ,143 ,16 ,167 ,1 ,177 ,87 ,62 ,99 ,114 ,48 ,125 ,180 ,189 ,254 ,223 ,255 ,255 ,127 ,63 ,187 ,254 ,255 ,232 ,167 ,253 ,87 ,217 ,255 ,255 ,255 ,200 ,190 ,232 ,0 ,162 ,0 ,81 ,4 ,147 ,35 ,136 ,37 ,144 ,69 ,16 ,37 ,128 ,42 ,64 ,
100
- 160 ,21 ,64 ,20 ,66 ,17 ,136 ,34 ,200 ,146 ,196 ,145 ,195 ,215 ,168 ,127 ,138 ,117 ,10 ,37 ,138 ,20 ,128 ,197 ,195 ,32 ,88 ,151 ,33 ,212 ,201 ,226 ,200 ,245 ,234 ,226 ,255 ,254 ,167 ,73 ,0 ,5 ,2 ,195 ,11 ,243 ,2 ,225 ,95 ,223 ,191 ,255 ,127 ,255 ,250 ,255 ,122 ,136 ,66 ,41 ,4 ,80 ,10 ,32 ,138 ,32 ,74 ,17 ,68 ,18 ,64 ,21
101
- ]))
102
128
103
- parrotSprite = grayscale .Sprite (72 , 40 , bytearray ([
104
- 64 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,40 ,24 ,36 ,156 ,46 ,94 ,63 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,254 ,254 ,252 ,244 ,240 ,240 ,224 ,192 ,128 ,0 ,0 ,0 ,0 ,0 ,160 ,128 ,128 ,128 ,128 ,0 ,0 ,0 ,0 ,0 ,
105
- 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,64 ,254 ,255 ,255 ,254 ,124 ,0 ,1 ,127 ,255 ,255 ,255 ,254 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,191 ,255 ,111 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,248 ,248 ,240 ,224 ,224 ,128 ,192 ,130 ,129 ,3 ,6 ,147 ,98 ,112 ,112 ,
106
- 128 ,128 ,128 ,128 ,128 ,0 ,0 ,0 ,0 ,0 ,0 ,128 ,135 ,207 ,223 ,231 ,224 ,0 ,0 ,0 ,3 ,7 ,7 ,15 ,15 ,31 ,31 ,63 ,255 ,127 ,255 ,255 ,127 ,255 ,191 ,111 ,191 ,119 ,95 ,183 ,79 ,191 ,95 ,191 ,95 ,7 ,23 ,143 ,223 ,247 ,255 ,247 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,245 ,215 ,111 ,255 ,255 ,255 ,253 ,252 ,241 ,192 ,132 ,
107
- 207 ,207 ,203 ,195 ,131 ,0 ,128 ,240 ,124 ,62 ,222 ,255 ,223 ,223 ,143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0 ,2 ,1 ,32 ,4 ,0 ,133 ,106 ,179 ,247 ,94 ,232 ,149 ,73 ,107 ,19 ,245 ,86 ,236 ,233 ,100 ,157 ,139 ,140 ,
112
- 0 ,64 ,64 ,64 ,0 ,128 ,0 ,0 ,88 ,40 ,192 ,1 ,105 ,50 ,32 ,24 ,31 ,254 ,223 ,222 ,188 ,75 ,187 ,23 ,247 ,9 ,231 ,193 ,15 ,129 ,6 ,0 ,130 ,0 ,64 ,144 ,64 ,136 ,160 ,72 ,176 ,64 ,160 ,64 ,160 ,248 ,232 ,112 ,32 ,8 ,0 ,8 ,0 ,0 ,0 ,1 ,23 ,14 ,60 ,48 ,32 ,10 ,40 ,145 ,1 ,3 ,5 ,18 ,3 ,14 ,63 ,91 ,
113
- 16 ,48 ,52 ,36 ,100 ,227 ,64 ,64 ,128 ,193 ,35 ,1 ,42 ,33 ,112 ,108 ,96 ,222 ,248 ,242 ,204 ,187 ,73 ,255 ,251 ,223 ,227 ,252 ,91 ,247 ,94 ,121 ,252 ,252 ,191 ,254 ,189 ,252 ,223 ,126 ,249 ,253 ,250 ,252 ,255 ,253 ,122 ,244 ,57 ,222 ,42 ,156 ,170 ,78 ,24 ,165 ,74 ,16 ,68 ,16 ,192 ,16 ,161 ,71 ,24 ,250 ,232 ,128 ,104 ,128 ,4 ,184 ,
114
- 201 ,130 ,199 ,100 ,67 ,239 ,1 ,150 ,241 ,112 ,114 ,124 ,249 ,182 ,8 ,85 ,251 ,239 ,191 ,253 ,251 ,223 ,253 ,239 ,191 ,250 ,231 ,155 ,79 ,192 ,211 ,253 ,239 ,125 ,255 ,127 ,221 ,127 ,175 ,127 ,255 ,95 ,255 ,111 ,255 ,124 ,247 ,188 ,235 ,188 ,234 ,77 ,176 ,74 ,181 ,66 ,121 ,68 ,169 ,66 ,244 ,191 ,74 ,150 ,45 ,127 ,191 ,255 ,236 ,128 ,253 ,123
115
- ]))
116
-
117
- gs .drawSprite (girlSprite )
118
- waitKey ()
119
-
120
- gs .drawSprite (parrotSprite )
121
- waitKey ()
129
+ # Wait for key release
130
+ while actionPressed (): pass
131
+
132
+ # Bounce animation using drawing primitives
133
+
134
+ fps = - 1
135
+ dx = 1
136
+ dy = 0
137
+ x = y = 0
138
+ frame_rate = 30
139
+ frame_microsec = int (1000000.0 / frame_rate )
140
+ while not actionPressed ():
141
+ t0 = ticks_us ()
142
+ gs .fill (3 )
143
+ gs .drawFilledRectangle (x , y + 0 , 12 , 4 , gs .LIGHTGRAY )
144
+ gs .drawFilledRectangle (x , y + 4 , 12 , 4 , gs .DARKGRAY )
145
+ gs .drawFilledRectangle (x , y + 8 , 12 , 4 , gs .BLACK )
146
+
147
+ gs .setPixel (0 , 0 , gs .BLACK )
148
+ gs .setPixel (71 , 0 , gs .BLACK )
149
+ gs .setPixel (0 , 39 , gs .BLACK )
150
+ gs .setPixel (71 , 39 , gs .BLACK )
151
+ gs .drawText (str (fps >> 4 ), 2 , 2 , gs .LIGHTGRAY )
152
+
153
+ gs .show ()
154
+
155
+ x += dx
156
+ if x < 0 or x > 72 - 12 :
157
+ dx = - dx
158
+ y += dy >> 16
159
+ dy += 16384
160
+ if y >= 30 :
161
+ dy = (- dy * 50000 ) >> 16
162
+
163
+ td = ticks_diff (ticks_us (), t0 )
164
+ if td == 0 :
165
+ td = 1
166
+ fpsn = (1000000 << 4 )// td
167
+ if fps == - 1 :
168
+ fps = fpsn
169
+ else :
170
+ fps += (fpsn - fps ) >> 5
171
+ sleep_ms ((frame_microsec - ticks_diff (ticks_us (), t0 )) >> 10 )
172
+ sleep_us (frame_microsec - ticks_diff (ticks_us (), t0 ) - 12 )
173
+
174
+ # End of demo!
122
175
123
176
gs .stop ()
124
-
125
- thumby .reset ()
177
+ reset ()
0 commit comments