Skip to content

Instantly share code, notes, and snippets.

@theacodes
Created May 30, 2024 15:51
Show Gist options
  • Save theacodes/23667e827fbfa5a16d19dadb5bee19d3 to your computer and use it in GitHub Desktop.
Save theacodes/23667e827fbfa5a16d19dadb5bee19d3 to your computer and use it in GitHub Desktop.
Angel lamp code
import time
import board
from digitalio import DigitalInOut, Direction
import pwmio
import math
pwm = pwmio.PWMOut(board.TX, frequency=60)
pwm.duty_cycle = 0
FULL = 0xFFFF
bursts = [
[1, 0],
[0.05, FULL],
[0.1, 0],
[0.05, FULL],
[0.1, 0],
[0.022, FULL],
[0.051, 0],
[0.11, 0],
[0.03, FULL],
[0.012, 0],
[10, FULL],
]
burst_idx = 0
fast_theta = 0
slow_theta = 0
lum = 0
next_at = time.monotonic()
fast_mod_depth = 4000
slow_mod_depth = 20000
while True:
now = time.monotonic()
fast_theta += 0.125
fast_mod = fast_mod_depth + int(math.sin(fast_theta) * fast_mod_depth)
slow_theta += 0.0025
slow_mod = int(math.sin(slow_theta) * slow_mod_depth)
mod_lum = max(0, min(lum - fast_mod - slow_mod, FULL))
pwm.duty_cycle = mod_lum
if now > next_at:
duration, lum = bursts[burst_idx]
next_at = now + duration
burst_idx += 1
if(burst_idx == len(bursts)):
burst_idx = 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment