Skip to content

Instantly share code, notes, and snippets.

@boochow
Created November 17, 2018 12:58
Show Gist options
  • Select an option

  • Save boochow/c82e3f39cd43c1153b7a53ade71455d2 to your computer and use it in GitHub Desktop.

Select an option

Save boochow/c82e3f39cd43c1153b7a53ade71455d2 to your computer and use it in GitHub Desktop.
def uint32(x):
if x & 0x8000000:
x = x - 0xffffffff - 1
return x
def byte2pwm(b):
bits = "{:08b}".format(b)
data = 0
for c in bits:
data = (data << 4) | (0b1000 if c == '0' else 0b1110)
return data
def neopixel_pwm(p, l):
p.active(False)
p.fifo_clear()
for i in l:
p.fifo_queue(uint32(byte2pwm(i)))
p.fifo_queue(0)
p.active(True)
from machine import Clock, PWM, Pin
import time
Clock(Clock.PWM, enable=False, source=Clock.OSC, divi=5, divf=0, mash=0)
Clock(Clock.PWM, enable=True)
p = PWM(Pin(18), mode=PWM.MODE_SERIALIZER, active=0, tick_hz=3200000, duty_ticks=0, period=32, ms=PWM.MS_ENABLE, use_fifo=1, fifo_repeat=1)
neopixel_pwm(p,[50,0,0,0,50,0,0,0,50,25,25,0,0,25,25])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment