update neopixel to enw numbering

master
Ondřej Hruška 7 years ago
parent 7e9f6f1c3c
commit e00a5b25d9
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 2
      demo_adc_lightnings.py
  2. 4
      demo_neo2.py
  3. 39
      demo_neo3.py
  4. 6
      gex/units/Neopixel.py

@ -21,7 +21,7 @@ def capture(tr):
print("Capture! ")
print(data)
np.save("lightning-%s"%now.isoformat(), data)
led.pulse_ms(250, confirm=False)
led.pulse_ms(1000, confirm=False)
with gex.Client(gex.TrxRawUSB()) as client:
adc = gex.ADC(client, 'adc')

@ -4,12 +4,12 @@ import time
with gex.Client(gex.TrxRawUSB()) as client:
# Neopixel strip
strip = gex.Neopixel(client, 'neo')
strip = gex.Neopixel(client, 'npx')
# Load RGB to the strip
strip.load([0xFF0000, 0xFFFF00, 0x00FF00, 0x0000FF, 0xFF00FF])
for i in range(0,255):
strip.load([0xFF0000+i, 0xFFFF00, 0x00FF00, 0x0000FF, 0xFF00FF])
time.sleep(0.001)
time.sleep(0.01)
strip.clear()

@ -0,0 +1,39 @@
#!/bin/env python3
import gex
import time
# this shows a spinny animation on a 30-pixel strip forming a circle
def draw_comet(buf, index):
r = 0xFF
g = 0x22
b = 0x00
steps = 5
fades = [0.05, 1, 0.5, 0.1, 0.05]
for i in range(steps):
fade = fades[i]
buf[(len(buf) + index - i)%len(buf)] = \
round(r * fade)<<16 | \
round(g * fade)<<8 | \
round(b * fade)
with gex.Client(gex.TrxRawUSB()) as client:
# Neopixel strip
strip = gex.Neopixel(client, 'npx')
markers = [0, 15]
for i in range(1000):
buf = [0]*30
for j in range(len(markers)):
n = markers[j]
draw_comet(buf, n)
n = n + 1 if n < len(buf)-1 else 0
markers[j] = n
strip.load(buf)
time.sleep(0.02)
strip.clear()

@ -10,7 +10,7 @@ class Neopixel(gex.Unit):
def get_len(self):
""" Get the neopixel strip length """
resp = self._query(0x04)
resp = self._query(10)
pp = gex.PayloadParser(resp)
return pp.u16()
@ -24,10 +24,10 @@ class Neopixel(gex.Unit):
pb = gex.PayloadBuilder(endian='big' if reverse else 'little')
for c in colors:
pb.u24(c)
self._send(0x01, pb.close(), confirm=confirm)
self._send(1, pb.close(), confirm=confirm)
def clear(self, confirm=True):
"""
Reset the strip (set all to black)
"""
self._send(0x00, confirm=confirm)
self._send(0, confirm=confirm)

Loading…
Cancel
Save