Toggle Navigation
Hatchery
Eggs
artichoke
__init__.py
Users
Badges
Login
Register
MCH2022 badge?
go to mch2022.badge.team
__init__.py
raw
Content
import display, time, random, neopixel, _thread, buttons neopixel.enable() class Fukk: def __init__(self): self.led_speed = 5 self.led_data = [0]*36 def led_speed_increase(self, pressed): if pressed and self.led_speed > 1: self.led_speed -= 1 def led_speed_decrease(self, pressed): if pressed and self.led_speed < 10: self.led_speed += 1 def start_loop(self): _thread.start_new_thread("leds", self.blink_leds, []) _thread.start_new_thread("display", self.display_loop, []) def display_loop(self): while True: self.do_for_seconds(6, self.anim) self.do_for_seconds(2, self.write_text, "turn on") self.do_for_seconds(2, self.write_text, "tune in") self.do_for_seconds(2, self.write_text, "drop out") def text_center_position(self, text, font): return int((display.width() - display.getTextWidth(text, font)) / 2), int((display.height() - display.getTextHeight(text, font)) / 2) def write_shadowed_text(self, text, font): text_x_position, text_y_position = self.text_center_position(text, font) display.drawText(text_x_position, text_y_position, text, 0xFFFFFF, font) display.drawText(text_x_position-3, text_y_position-3, text, 0x000000, font) def write_text(self, text): display.drawFill(0x000000) for _ in range(40): display.drawLine( 0, random.randint(0, display.height()), display.width(), random.randint(0, display.height()), 0xFAFAFAFA) self.write_shadowed_text(text, "permanentmarker22") display.flush() def anim(self): for i in range(128): display.drawFill(0x000000) if i > 64: i = 128 - i for _ in range(40): display.drawLine( 0, random.randint(0, display.height()), display.width(), random.randint(0, display.height()), 0xFAFAFAFA) display.drawCircle(int(display.width()/2), int(display.height()/2), i, 0, 360, True, 0x000000) display.drawCircle(int(display.width()/2), int(display.height()/2), int(i/2), 0, 360, False, 0xFFFFFF) display.drawCircle(int(display.width()/2), int(display.height()/2), int(i/4), 0, 360, True, 0xFFFFFF) display.flush() time.sleep_ms(1) def blink_leds(self): while True: for i in range(128): if i > 64: i = 128 - i for x in range(12): self.led_data[3*x] = i self.led_data[3*x+2] = i neopixel.send(bytes(self.led_data)) time.sleep_ms(self.led_speed) def do_for_seconds(self, seconds, action, *args): t_end = time.time() + seconds while time.time() < t_end: action(*args) a = Fukk() buttons.attach(buttons.BTN_UP, a.led_speed_increase) buttons.attach(buttons.BTN_DOWN, a.led_speed_decrease) a.start_loop()