import utime class StrobeBurst: def __init__(self, driver): self.driver = driver def run(self, preset): colors = preset.c if preset.c else [(255, 255, 255)] state = "flash_on" flash_idx = 0 state_start = utime.ticks_ms() while True: count = max(1, int(preset.n1) if int(preset.n1) > 0 else 3) gap = max(1, int(preset.n2) if int(preset.n2) > 0 else 60) cooldown = max(1, int(preset.n3) if int(preset.n3) > 0 else 400) on_ms = max(1, int(preset.d) // 2) c = self.driver.apply_brightness(colors[0], preset.b) bg_color = self.driver.apply_brightness(preset.background_or(colors), preset.b) now = utime.ticks_ms() if state == "flash_on": self.driver.fill(c) if utime.ticks_diff(now, state_start) >= on_ms: state = "flash_off" state_start = utime.ticks_add(state_start, on_ms) elif state == "flash_off": self.driver.fill(bg_color) if utime.ticks_diff(now, state_start) >= gap: flash_idx += 1 if flash_idx >= count: if not preset.a: return state = "cooldown" flash_idx = 0 state_start = utime.ticks_add(state_start, gap) else: state = "flash_on" state_start = utime.ticks_add(state_start, gap) else: self.driver.fill(bg_color) if utime.ticks_diff(now, state_start) >= cooldown: state = "flash_on" state_start = utime.ticks_add(state_start, cooldown) yield