|
| 1 | +from thumbyGraphics import display as d |
| 2 | +import thumbyButton as b |
| 3 | +from thumbyAudio import audio as a |
| 4 | +from thumby import Sprite as S |
| 5 | +from time import ticks_ms as t |
| 6 | + |
| 7 | +# BITMAP: width: 9, height: 8 |
| 8 | +bitmap1 = bytearray([0,66,165,153,129,153,165,66,0]) |
| 9 | +timerSprite = S(9, 8, bitmap1, 0, 1) |
| 10 | + |
| 11 | +# BITMAP: width: 9, height: 8 |
| 12 | +bitmap2 = bytearray([0,56,68,131,155,131,68,58,0]) |
| 13 | +stopwatchSprite = S(9, 8, bitmap2, 0, 1) |
| 14 | + |
| 15 | +# BITMAP: width: 3, height: 5 |
| 16 | +bitmap3 = bytearray([4,14,31]) |
| 17 | +leftSprite = S(3, 5, bitmap3, 0, 3) |
| 18 | + |
| 19 | +# BITMAP: width: 3, height: 5 |
| 20 | +bitmap4 = bytearray([31,14,4]) |
| 21 | +rightSprite = S(3, 5, bitmap4, 0, 3) |
| 22 | + |
| 23 | +# BITMAP: width: 5, height: 3 |
| 24 | +bitmap5 = bytearray([4,6,7,6,4]) |
| 25 | +upSprite = S(5, 3, bitmap5, 0, 10) |
| 26 | + |
| 27 | +# BITMAP: width: 5, height: 3 |
| 28 | +bitmap6 = bytearray([1,3,7,3,1]) |
| 29 | +downSprite = S(5, 3, bitmap6, 0, 20) |
| 30 | + |
| 31 | +# BITMAP: width: 10, height: 7 |
| 32 | +bitmap7 = bytearray([28,62,67,117,67,62,28,0,54,54]) |
| 33 | +ASprite = S(10, 7, bitmap7, 1, 32) |
| 34 | + |
| 35 | +# BITMAP: width: 10, height: 7 |
| 36 | +bitmap8 = bytearray([28,62,65,85,75,62,28,0,54,54]) |
| 37 | +BSprite = S(10, 7, bitmap8, 55, 32) |
| 38 | + |
| 39 | +playSprite = S(3, 5, bitmap4, 13, 33) |
| 40 | + |
| 41 | +# BITMAP: width: 5, height: 5 |
| 42 | +bitmap11 = bytearray([31,31,0,31,31]) |
| 43 | +pauseSprite = S(5, 5, bitmap11, 13, 33) |
| 44 | + |
| 45 | +# BITMAP: width: 5, height: 5 |
| 46 | +bitmap12 = bytearray([14,25,21,19,14]) |
| 47 | +noneSprite = S(5, 5, bitmap12, 66, 33) |
| 48 | + |
| 49 | +# BITMAP: width: 5, height: 5 |
| 50 | +bitmap13 = bytearray([31,31,31,31,31]) |
| 51 | +stopSprite = S(5, 5, bitmap13, 66, 33) |
| 52 | + |
| 53 | +# BITMAP: width: 5, height: 5 |
| 54 | +bitmap14 = bytearray([0,31,7,2,0]) |
| 55 | +flagSprite = S(5, 5, bitmap14, 66, 33) |
| 56 | + |
| 57 | +# BITMAP: width: 5, height: 5 |
| 58 | +bitmap15 = bytearray([14,17,23,25,14]) |
| 59 | +timeSprite = S(5, 5, bitmap15, 66, 33) |
| 60 | + |
| 61 | +# BITMAP: width: 5, height: 5 |
| 62 | +bitmap16 = bytearray([2,30,19,30,2]) |
| 63 | +deleteSprite = S(5, 5, bitmap16, 66, 33) |
| 64 | + |
| 65 | +# BITMAP: width: 5, height: 5 |
| 66 | +bitmap17 = bytearray([14,17,16,22,14]) |
| 67 | +resetSprite = S(5, 5, bitmap17, 66, 33) |
| 68 | + |
| 69 | +# BITMAP: width: 5, height: 5 |
| 70 | +bitmap18 = bytearray([21,5,29,1,31]) |
| 71 | +scaleSprite = S(5, 5, bitmap18, 66, 33) |
| 72 | + |
| 73 | +# BITMAP: width: 5, height: 5 |
| 74 | +bitmap19 = bytearray([8,16,8,4,2]) |
| 75 | +checkSprite = S(5, 5, bitmap19, 13, 33) |
| 76 | + |
| 77 | +# BITMAP: width: 3, height: 5 |
| 78 | +bitmap20 = bytearray([18,23,18]) |
| 79 | +PMSprite = S(3, 5, bitmap20, 28, 33) |
| 80 | + |
| 81 | +framecounter = 0 |
| 82 | +xScroll = xScrollTar = 0 |
| 83 | +yScroll = yScrollTar = 0 |
| 84 | + |
| 85 | +d.setFPS(60) |
| 86 | + |
| 87 | +def printlist(listtoprint, selection, yOffset): |
| 88 | + d.drawText(listtoprint[selection-1] if selection > 0 else '', 7, 49-yOffset, 1) |
| 89 | + d.drawText('>', 0, 57-yOffset, 1) |
| 90 | + d.drawText(listtoprint[selection], 7, 57-yOffset, 1) |
| 91 | + d.drawText(listtoprint[selection+1] if selection < len(listtoprint) - 1 else '', 7, 65-yOffset, 1) |
| 92 | + |
| 93 | +timerM = timerS = timerMS = 0 |
| 94 | +stopwatchM = stopwatchS = stopwatchMS = 0 |
| 95 | +isStopwatch = isTimer = 0 |
| 96 | +stopwatchData = '' |
| 97 | +timerData = '' |
| 98 | +startTimerData = [timerM, timerS, timerMS] |
| 99 | +flags = [] |
| 100 | +flagSel = 0 |
| 101 | +lastStopwatchTime = 0 |
| 102 | +isSettingTimer = 0 |
| 103 | +timeScale = 0 |
| 104 | +timerSel = 0 |
| 105 | +timerDone = 0 |
| 106 | +flash = 0 |
| 107 | + |
| 108 | +while(1): |
| 109 | + framecounter += 1 |
| 110 | + d.fill(flash) |
| 111 | + if isStopwatch: |
| 112 | + stopwatchTime = t()-stopwatchStart+lastStopwatchTime |
| 113 | + stopwatchMS = (stopwatchTime % 1000) // 10 |
| 114 | + stopwatchS = (stopwatchTime // 1000) % 60 |
| 115 | + stopwatchM = stopwatchTime // 60000 |
| 116 | + if isTimer: |
| 117 | + timerTime = t()-timerStart |
| 118 | + timerRemaining = timerTotal-timerTime |
| 119 | + timerMS = (timerRemaining % 1000) // 10 |
| 120 | + timerS = (timerRemaining // 1000) % 60 |
| 121 | + timerM = timerRemaining // 60000 |
| 122 | + if (timerM or timerS or timerMS) < 0: |
| 123 | + isTimer = 0 |
| 124 | + timerDone = 1 |
| 125 | + if timerDone: |
| 126 | + if framecounter % 30 == 0: |
| 127 | + flash = not flash |
| 128 | + a.play(1500 if flash else 500, 30) |
| 129 | + timerM, timerS, timerMS = 0, 0, 0 |
| 130 | + yScrollTar, yScroll = 0, 0 |
| 131 | + xScrollTar, xScroll = 72, 72 |
| 132 | + if xScroll in range(0, 72): |
| 133 | + stopwatchData = f'{stopwatchM:02}:{stopwatchS:02}.{stopwatchMS:02}' |
| 134 | + d.drawText(stopwatchData, stopwatchSprite.x-19, 17-yScroll, not flash) |
| 135 | + d.drawFilledRectangle(0, 0, 72, 10, 0) |
| 136 | + if flags: |
| 137 | + if yScroll in range(0, 21): |
| 138 | + downSprite.y = stopwatchSprite.y + 4 |
| 139 | + downSprite.x = stopwatchSprite.x - 5 |
| 140 | + d.drawSprite(downSprite) |
| 141 | + elif yScroll in range(21, 41): |
| 142 | + upSprite.y = stopwatchSprite.y + 2 |
| 143 | + upSprite.x = stopwatchSprite.x - 5 |
| 144 | + d.drawSprite(upSprite) |
| 145 | + if yScroll: |
| 146 | + printlist(flags, flagSel, yScroll) |
| 147 | + d.drawSprite(stopwatchSprite) |
| 148 | + if not yScroll: |
| 149 | + rightSprite.x = stopwatchSprite.x + 9 |
| 150 | + d.drawSprite(rightSprite) |
| 151 | + if xScroll in range(1, 73): |
| 152 | + d.drawSprite(timerSprite) |
| 153 | + if timerDone: |
| 154 | + d.drawRectangle(timerSprite.x, timerSprite.y-1, 9, 10, 0) |
| 155 | + leftSprite.x = timerSprite.x - 3 |
| 156 | + if not isSettingTimer: |
| 157 | + if not timerDone: |
| 158 | + d.drawSprite(leftSprite) |
| 159 | + else: |
| 160 | + upSprite.y = 13 |
| 161 | + downSprite.y = 25 |
| 162 | + upSprite.x = 15 + 18*timerSel |
| 163 | + downSprite.x = 15 + 18*timerSel |
| 164 | + d.drawSprite(upSprite) |
| 165 | + d.drawSprite(downSprite) |
| 166 | + d.drawSprite(PMSprite) |
| 167 | + d.drawText('1'+'0'*timeScale, 33-2*timeScale, 32, 1) |
| 168 | + timerData = f'{timerM:02}:{timerS:02}.{timerMS:02}' if not isSettingTimer else f'{startTimerData[0]:02}:{startTimerData[1]:02}.{startTimerData[2]:02}' |
| 169 | + d.drawText(timerData, timerSprite.x-20-(6 if startTimerData[0]>99 else 0), 17, not flash) |
| 170 | + if (xScroll == 0 or xScroll == 72) and (yScroll == 0 or yScroll == 40): |
| 171 | + if not timerDone: |
| 172 | + d.drawSprite(ASprite) |
| 173 | + d.drawSprite(BSprite) |
| 174 | + if not xScroll: |
| 175 | + if not yScroll: |
| 176 | + d.drawSprite(pauseSprite if isStopwatch else playSprite) |
| 177 | + if not isStopwatch: |
| 178 | + noneSprite.x = 66 |
| 179 | + d.drawSprite(stopSprite if stopwatchMS else noneSprite) |
| 180 | + else: |
| 181 | + d.drawSprite(flagSprite) |
| 182 | + else: |
| 183 | + noneSprite.x = 13 |
| 184 | + d.drawSprite(noneSprite) |
| 185 | + d.drawSprite(deleteSprite) |
| 186 | + else: |
| 187 | + if not isSettingTimer: |
| 188 | + if timerM or timerS or timerMS: |
| 189 | + d.drawSprite(pauseSprite if isStopwatch else playSprite) |
| 190 | + else: |
| 191 | + noneSprite.x = 13 |
| 192 | + d.drawSprite(noneSprite) |
| 193 | + if timerMS or timerS or timerM: |
| 194 | + if timerData != f'{startTimerData[0]:02}:{startTimerData[1]:02}.{startTimerData[2]:02}': |
| 195 | + if isTimer: |
| 196 | + noneSprite.x = 66 |
| 197 | + d.drawSprite(noneSprite) |
| 198 | + else: |
| 199 | + d.drawSprite(resetSprite) |
| 200 | + else: |
| 201 | + d.drawSprite(stopSprite) |
| 202 | + else: |
| 203 | + d.drawSprite(timeSprite) |
| 204 | + else: |
| 205 | + d.drawSprite(checkSprite) |
| 206 | + d.drawSprite(scaleSprite) |
| 207 | + timerSprite.x = 72-xScroll+32 |
| 208 | + stopwatchSprite.x = -xScroll+32 |
| 209 | + d.update() |
| 210 | + if b.buttonL.justPressed(): |
| 211 | + if timerDone: |
| 212 | + flash = 0 |
| 213 | + timerDone = 0 |
| 214 | + else: |
| 215 | + if not yScroll: |
| 216 | + if not isSettingTimer: |
| 217 | + xScrollTar = max(0, xScrollTar-72) |
| 218 | + else: |
| 219 | + timerSel = max(0, timerSel-1) |
| 220 | + elif b.buttonR.justPressed(): |
| 221 | + if not yScroll: |
| 222 | + if not isSettingTimer: |
| 223 | + xScrollTar = min(72, xScrollTar+72) |
| 224 | + else: |
| 225 | + timerSel = min(2, timerSel+1) |
| 226 | + if b.buttonU.justPressed(): |
| 227 | + if timerDone: |
| 228 | + flash = 0 |
| 229 | + timerDone = 0 |
| 230 | + else: |
| 231 | + if not xScroll: |
| 232 | + if flagSel == 0: |
| 233 | + yScrollTar = max(0, yScrollTar-40) |
| 234 | + else: |
| 235 | + flagSel = max(0, flagSel-1) |
| 236 | + else: |
| 237 | + if isSettingTimer: |
| 238 | + startTimerData[timerSel] += 10 if timeScale else 1 |
| 239 | + if startTimerData[0] > 119: |
| 240 | + startTimerData[0] = 0 |
| 241 | + if startTimerData[1] > 59: |
| 242 | + startTimerData[1] = 0 |
| 243 | + if startTimerData[2] > 99: |
| 244 | + startTimerData[2] = 0 |
| 245 | + elif b.buttonD.justPressed(): |
| 246 | + if timerDone: |
| 247 | + flash = 0 |
| 248 | + timerDone = 0 |
| 249 | + else: |
| 250 | + if not xScroll: |
| 251 | + if flags: |
| 252 | + if not yScroll: |
| 253 | + yScrollTar = min(40, yScrollTar+40) |
| 254 | + else: |
| 255 | + flagSel = min(len(flags)-1, flagSel+1) |
| 256 | + else: |
| 257 | + if isSettingTimer: |
| 258 | + startTimerData[timerSel] -= 10 if timeScale else 1 |
| 259 | + if startTimerData[0] < 0: |
| 260 | + startTimerData[0] = 119 |
| 261 | + if startTimerData[1] < 0: |
| 262 | + startTimerData[1] = 59 |
| 263 | + if startTimerData[2] < 0: |
| 264 | + startTimerData[2] = 99 |
| 265 | + if b.buttonA.justPressed(): |
| 266 | + if timerDone: |
| 267 | + flash = 0 |
| 268 | + timerDone = 0 |
| 269 | + else: |
| 270 | + if not xScroll: |
| 271 | + if not isStopwatch: |
| 272 | + if stopwatchMS or stopwatchS or stopwatchM: lastStopwatchTime = stopwatchTime |
| 273 | + stopwatchStart = t() |
| 274 | + isStopwatch = not isStopwatch |
| 275 | + else: |
| 276 | + if isSettingTimer: |
| 277 | + timerM, timerS, timerMS = startTimerData |
| 278 | + isSettingTimer = 0 |
| 279 | + elif timerM or timerS or timerMS: |
| 280 | + timerStart = t() |
| 281 | + timerTotal = (timerM*60+timerS)*1000+timerMS |
| 282 | + isTimer = not isTimer |
| 283 | + if b.buttonB.justPressed(): |
| 284 | + if timerDone: |
| 285 | + flash = 0 |
| 286 | + timerDone = 0 |
| 287 | + else: |
| 288 | + if not xScroll: |
| 289 | + if not yScroll: |
| 290 | + if not isStopwatch and stopwatchMS: |
| 291 | + stopwatchM = stopwatchS = stopwatchMS = 0 |
| 292 | + lastStopwatchTime = 0 |
| 293 | + flags = [] |
| 294 | + elif isStopwatch: |
| 295 | + flags.insert(0, stopwatchData) |
| 296 | + elif yScroll == 40: |
| 297 | + flags.pop(flagSel) |
| 298 | + if not flags: |
| 299 | + yScrollTar = 0 |
| 300 | + elif xScroll == 72: |
| 301 | + if not isSettingTimer: |
| 302 | + if timerM or timerS or timerMS: |
| 303 | + if not isTimer: |
| 304 | + if timerData != f'{startTimerData[0]:02}:{startTimerData[1]:02}.{startTimerData[2]:02}': |
| 305 | + timerM, timerS, timerMS = startTimerData |
| 306 | + isTimer = 0 |
| 307 | + else: |
| 308 | + timerM, timerS, timerMS = 0, 0, 0 |
| 309 | + startTimerData = [timerM, timerS, timerMS] |
| 310 | + else: |
| 311 | + isSettingTimer = 1 |
| 312 | + else: |
| 313 | + timeScale = not timeScale |
| 314 | + if xScrollTar < xScroll: |
| 315 | + xScroll -= 4 |
| 316 | + elif xScrollTar > xScroll: |
| 317 | + xScroll += 4 |
| 318 | + if yScrollTar < yScroll: |
| 319 | + yScroll -= 2 |
| 320 | + elif yScrollTar > yScroll: |
| 321 | + yScroll += 2 |
0 commit comments