Toggle Navigation
Hatchery
Eggs
Flashlight with On/Off Switch
flashlight.py
Users
Badges
Login
Register
MCH2022 badge?
go to mch2022.badge.team
flashlight.py
raw
Content
import display import leds import color import utime import buttons # 1 = ON, 0 = Off flashStatus = 1 def CheckButton(): global flashStatus pressed = buttons.read( buttons.BOTTOM_LEFT | buttons.BOTTOM_RIGHT ) if pressed: if flashStatus: FlashOff() flashStatus = 0 else: FlashOn() flashStatus = 1 def FlashOn(): leds.dim_top(8) leds.dim_bottom(8) leds.set_rocket(0, 31) leds.set_rocket(1, 31) leds.set_rocket(2, 31) leds.set_all([color.WHITE] * 15) with display.open() as d: d.rect(0, 0, 160, 80, col=color.WHITE) d.update() def FlashOff(): bri = 0 leds.dim_top(bri) leds.dim_bottom(bri) leds.set_rocket(0, bri) leds.set_rocket(1, bri) leds.set_rocket(2, bri) leds.set_all([color.BLACK] * 15) with display.open() as d: d.rect(0, 0, 160, 80, col=color.BLACK) d.update() FlashOn() while True: utime.sleep_ms(200) CheckButton()