Toggle Navigation
Hatchery
Eggs
colorwheel
__init__.py
Users
Badges
Login
Register
MCH2022 badge?
go to mch2022.badge.team
__init__.py
raw
Content
import display, time, version, neopixel, buttons #, _thread, system neopixel.enable() display.drawFill(0x000000) display.drawText(0,0,version.badge_name, 0xFFFFFF, "7x5") display.drawText(0,6,version.name, 0xFFFFFF, "7x5") display.drawText(0,12,"Build "+str(version.build), 0xFFFFFF, "7x5") display.drawText(0,18,"EHLOx", 0xFFFFFF, "7x5") display.flush() ledStop = False class colorwheel: def __init__(self): self.running = True self.dimmer = 2 self.speed = 10 def updateDisplay(self): display.drawFill(0x000000) display.drawText(0,0,"Wheeee", 0xFFFFFF, "7x5") display.drawText(0,6,"Dim " + str(self.dimmer), 0xFFFFFF, "7x5") display.drawText(0,12,"Spd " + str(self.speed), 0xFFFFFF, "7x5") display.flush() def bright(self, pressed): if pressed: self.dimmer -= 1 if self.dimmer < 0: self.dimmer = 0 self.updateDisplay() def dim(self, pressed): if pressed: self.dimmer += 1 if self.dimmer > 7: self.dimmer = 7 self.updateDisplay() def slower(self, pressed): if pressed: self.speed -= 1 if self.speed < 0: self.speed = 0 self.updateDisplay() def faster(self, pressed): if pressed: self.speed += 2 if self.speed > 20: self.speed = 20 self.updateDisplay() def ledProc(self): self.updateDisplay() ledState = 0 ledData = [0x00, 0x00, 0x00]*12 while True: for i in range(len(ledData)): if ledData[i] > 64: ledData[i] -= 64 else: ledData[i] = 0 if self.running: for i in range(12): color = (ledState*self.speed + i*10) % 255 if color < 85: ledData[3*i] = (255 - color * 3) >> self.dimmer ledData[3*i+1] = 0 ledData[3*i+2] = (color * 3) >> self.dimmer elif color < 170: color -= 85 ledData[3*i+2] = (255 - color * 3) >> self.dimmer ledData[3*i] = 0 ledData[3*i+1] = (color * 3) >> self.dimmer else: color -= 170 ledData[3*i+1] = (255 - color * 3) >> self.dimmer ledData[3*i+2] = 0 ledData[3*i] = (color * 3) >> self.dimmer neopixel.send(bytes(ledData)) ledState = ledState + 1 if ledState > 254: ledState = 0 time.sleep_ms(20) a = colorwheel() #_thread.start_new_thread("LED", ledThread, ()) buttons.attach(buttons.BTN_UP, a.bright) buttons.attach(buttons.BTN_DOWN, a.dim) buttons.attach(buttons.BTN_LEFT, a.slower) buttons.attach(buttons.BTN_RIGHT, a.faster) a.ledProc()