Toggle Navigation
Hatchery
Eggs
ColorfulFlashlight
__init__.py
Users
Badges
Login
Register
MCH2022 badge?
go to mch2022.badge.team
__init__.py
raw
Content
##################################### # ColorfulFlashlight by CryptKiddie # ##################################### # imports import leds import vibra import urandom import buttons from utime import sleep # vars vibrate=True color_concepts=[[255,255,255],[0,0,255],[0,255,0],[255,0,0],"rnd"] brightness_leds=[1,8] brightness_screen=[10,100] recolorize_delay=0.2 color_concept=0 led_brightness=1 # functions for color change def recolorize(rgb): if (rgb == "rnd"): for x in range(0,14): leds.set(x,[urandom.randint(0,255),urandom.randint(0,255),urandom.randint(0,255)]) sleep(recolorize_delay) else: for x in range(0,14): leds.set(x,rgb) sleep(recolorize_delay) def select_concept(id): recolorize(color_concepts[color_concept]) def inc_color_concept(): global color_concept color_concept = (color_concept +1) % len(color_concepts) select_concept(color_concept) # functions for brightness change def dim_all(brightness): leds.dim_top(brightness) leds.dim_bottom(brightness) def inc_dim(): global led_brightness led_brightness = (led_brightness +1) % 9 dim_all(led_brightness) # alert procedure def alert(t): dim_all(8) for x in range(0,2): leds.set_rocket(x,8) vibra.set(vibrate) sleep(t) dim_all(1) sleep(t) for x in range(0,2): leds.set_rocket(x,0) vibra.set(False) # Start of main code (Init LEDs) select_concept(color_concept) dim_all(led_brightness) # Main loop while (True): if (buttons.read(4) == 4): alert(0.2) if (buttons.read(2) == 2): inc_dim() if (buttons.read(1) == 1): inc_color_concept() sleep(0.2)