Toggle Navigation
Hatchery
Eggs
ChooChoo
__init__.py
Users
Badges
Login
Register
MCH2022 badge?
go to mch2022.badge.team
__init__.py
raw
Content
import vibra import utime import buttons import display import leds TRAINPX=[[17,1],[18,1],[19,1],[20,1],[21,1],[22,1],[25,1],[26,1],[16,2],[17,2],[18,2],[19,2],[20,2],[21,2],[22,2],[25,2],[26,2],[3,3],[4,3],[5,3],[6,3],[7,3],[8,3],[9,3],[10,3],[11,3],[12,3],[13,3],[16,3],[17,3],[18,3],[19,3],[20,3],[21,3],[22,3],[25,3],[26,3],[2,4],[3,4],[4,4],[5,4],[6,4],[7,4],[8,4],[9,4],[10,4],[11,4],[12,4],[13,4],[14,4],[16,4],[17,4],[18,4],[19,4],[20,4],[21,4],[22,4],[23,4],[24,4],[25,4],[26,4],[27,4],[2,5],[3,5],[4,5],[5,5],[6,5],[7,5],[8,5],[9,5],[10,5],[11,5],[12,5],[13,5],[14,5],[16,5],[17,5],[18,5],[19,5],[20,5],[21,5],[22,5],[23,5],[24,5],[25,5],[26,5],[27,5],[28,5],[2,6],[3,6],[4,6],[5,6],[6,6],[7,6],[8,6],[9,6],[10,6],[11,6],[12,6],[13,6],[14,6],[16,6],[17,6],[18,6],[19,6],[20,6],[21,6],[22,6],[23,6],[24,6],[25,6],[26,6],[27,6],[28,6],[2,7],[3,7],[4,7],[5,7],[6,7],[7,7],[8,7],[9,7],[10,7],[11,7],[12,7],[13,7],[14,7],[16,7],[17,7],[18,7],[19,7],[20,7],[21,7],[22,7],[23,7],[24,7],[25,7],[26,7],[27,7],[28,7],[29,7],[2,8],[3,8],[4,8],[5,8],[6,8],[7,8],[8,8],[9,8],[10,8],[11,8],[12,8],[13,8],[14,8],[15,8],[16,8],[17,8],[18,8],[19,8],[20,8],[21,8],[22,8],[23,8],[24,8],[25,8],[26,8],[27,8],[28,8],[29,8],[4,9],[5,9],[6,9],[10,9],[11,9],[12,9],[18,9],[19,9],[20,9],[25,9],[26,9],[27,9]] WAGGONPX=[[4,3],[5,3],[6,3],[7,3],[8,3],[9,3],[10,3],[11,3],[12,3],[13,3],[14,3],[3,4],[4,4],[5,4],[6,4],[7,4],[8,4],[9,4],[10,4],[11,4],[12,4],[13,4],[14,4],[15,4],[3,5],[4,5],[5,5],[6,5],[7,5],[8,5],[9,5],[10,5],[11,5],[12,5],[13,5],[14,5],[15,5],[3,6],[4,6],[5,6],[6,6],[7,6],[8,6],[9,6],[10,6],[11,6],[12,6],[13,6],[14,6],[15,6],[3,7],[4,7],[5,7],[6,7],[7,7],[8,7],[9,7],[10,7],[11,7],[12,7],[13,7],[14,7],[15,7],[2,8],[3,8],[4,8],[5,8],[6,8],[7,8],[8,8],[9,8],[10,8],[11,8],[12,8],[13,8],[14,8],[15,8],[16,8],[5,9],[6,9],[7,9],[11,9],[12,9],[13,9]] def v(x): t=x*10 vibra.vibrate(t) def s(x): t=x/10 utime.sleep(t) def choochoo(): leds.set(10,[200,200,0]) leds.set(9,[200,200,0]) clouds(2) v(5) s(2) leds.set(10,[0,0,0]) leds.set(9,[0,0,0]) leds.set(8,[200,200,0]) leds.set(7,[200,200,0]) clouds(0) v(5) s(2) leds.set(8,[0,0,0]) leds.set(7,[0,0,0]) leds.set(6,[200,200,0]) leds.set(5,[200,200,0]) clouds(1) v(5) s(2) leds.set(6,[0,0,0]) leds.set(5,[0,0,0]) leds.set(4,[200,200,0]) leds.set(3,[200,200,0]) clouds(0) v(5) s(2) leds.set(4,[0,0,0]) leds.set(3,[0,0,0]) leds.set(2,[200,200,0]) leds.set(1,[200,200,0]) clouds(2) v(5) s(2) leds.set(2,[0,0,0]) leds.set(1,[0,0,0]) leds.set(0,[200,200,0]) clouds(1) v(5) s(2) leds.set(0,[0,0,0]) def toot(): v(60) ledall(100,100,0) leds.set_rocket(0,10) leds.set_rocket(1,10) leds.set_rocket(2,10) s(10) ledall(200,200,0) leds.set_rocket(0,31) leds.set_rocket(1,31) leds.set_rocket(2,31) v(80) s(7) ledall(0,0,0) leds.set_rocket(0,0) leds.set_rocket(1,0) leds.set_rocket(2,0) def train(): while True: choochoo() pressed = buttons.read(buttons.TOP_RIGHT | buttons.BOTTOM_LEFT) if pressed & buttons.TOP_RIGHT != 0: toot() if pressed & buttons.BOTTOM_LEFT != 0: train_stop() break; def ledall(r,g,b): leds.set_all([[r,g,b],[r,g,b],[r,g,b],[r,g,b],[r,g,b],[r,g,b],[r,g,b],[r,g,b],[r,g,b],[r,g,b],[r,g,b]]) def train_go(): disp("train") ledall(0,50,0) clouds(1) v(5) s(8) ledall(0,60,0) v(5) s(7) ledall(0,70,0) v(5) s(6) ledall(0,80,0) clouds(2) v(5) s(5) ledall(0,90,0) v(5) s(4) ledall(0,100,0) clouds(0) v(5) s(3) ledall(0,150,0) clouds(2) v(5) s(3) clouds(1) v(5) s(2) train() def train_stop(): ledall(170,0,0) clouds(0) v(5) s(3) ledall(150,0,0) clouds(2) v(5) s(3) ledall(130,0,0) v(5) s(4) ledall(120,0,0) clouds(0) v(5) s(5) ledall(110,0,0) v(5) s(6) ledall(100,0,0) v(5) s(7) ledall(80,0,0) clouds(2) v(5) s(8) ledall(50,0,0) v(5) s(8) ledall(0,0,0) disp("info") def disp(mode): with display.open() as disp: disp.clear() disp.rect(0, 0, 160, 80, col=[0,200,255], filled=True)#heaven disp.print('ChooChoo!', font=display.FONT20, fg=[0,0,100], bg=[0,200,255], posx=20) if mode=="train": disp.rect(0, 70, 160, 80, col=[70,70,70], filled=True)#track for i, j in (TRAINPX): disp.pixel((i+60), (j+60), col=[50,50,50]) for i, j in (WAGGONPX): disp.pixel((i+45), (j+60), col=[50,50,50]) for i, j in (WAGGONPX): disp.pixel((i+30), (j+60), col=[50,50,50]) for i, j in (WAGGONPX): disp.pixel((i+15), (j+60), col=[50,50,50]) for i, j in (WAGGONPX): disp.pixel((i), (j+60), col=[50,50,50]) if mode=="info": disp.print('<back', font=display.FONT12, fg=[0,0,255], bg=[0,200,255], posy=20) disp.print('TOOT>', font=display.FONT12, fg=[0,0,255], bg=[0,200,255], posy=50, posx=120) disp.print('<STOP', font=display.FONT12, fg=[0,0,255], bg=[0,200,255], posy=65) disp.print('START>', font=display.FONT12, fg=[0,0,255], bg=[0,200,255], posy=65, posx=115) disp.update() def clouds(whichone): if whichone == 0: with display.open() as di: di.print('oO ooO o OO', font=display.FONT8, fg=[220,220,220], bg=[0,200,255], posx=32, posy=55) di.update() if whichone == 1: with display.open() as di: di.print('OO OOo o o.', font=display.FONT8, fg=[220,220,220], bg=[0,200,255], posx=32, posy=55) di.update() if whichone == 2: with display.open() as di: di.print('oo oOo O Oo', font=display.FONT8, fg=[220,220,220], bg=[0,200,255], posx=32, posy=55) di.update() def main(): disp("info") s(10) while True: pressed = buttons.read(buttons.TOP_RIGHT | buttons.BOTTOM_LEFT | buttons.BOTTOM_RIGHT) if pressed & buttons.TOP_RIGHT != 0: toot() if pressed & buttons.BOTTOM_RIGHT != 0: train_go() main()