Ejemplo n.º 1
0
class neo16x16:
    def __init__(self, pin):
        self.np = NeoPixel(pin, 256)
        self.color = (0,0,8)

    def clear(self):
        self.np.clear()

    def set(self, n, dat):
        self.np[n] = dat
        self.np.show()

    def setcolor(self, color):
        self.color = color

    def show(self, dat, pos=0, clear = True, color=''):
        if color != '':
            self.color = color
        if clear:
            for i in range(256):
                self.np[i]=(0,0,0)
        for x in range(16):
            for y in range(16):
                if (x+pos)>=len(dat):
                    self.np[x*16+y]=(0,0,0)
                else:
                    if (1<<y)&dat[x+pos]:
                        if pos%2==0:
                            self.np[x*16 + y] = self.color
                        else:
                            self.np[x*16 +15 - y] = self.color
        self.np.show()
Ejemplo n.º 2
0
class neo16x16_img:
    def __init__(self,pin):
        self.np=NeoPixel(pin,256)

    def clear(self):
        self.np.clear()

    def show(self,dat,pos=0):
        for x in range(16):
            for y in range(8):
                if ((x+pos)*8)>=len(dat):
                    self.np[x*16+y*2]=(0,0,0)
                    self.np[x*16+y*2+1]=(0,0,0)
                else:
                    t=dat[(x+pos)*8+y]
                    r=t%16
                    g=(t>>4)%16
                    b=(t>>8)%16
                    if pos%2:
                        self.np[x*16+y*2]=(r,g,b) 
                    else:
                        self.np[x*16+15-y*2]=(r,g,b)
                    r=(t>>12)%16
                    g=(t>>16)%16
                    b=(t>>20)%16
                    if pos%2:
                        self.np[x*16+y*2+1]=(r,g,b) 
                    else:
                        self.np[x*16+14-y*2]=(r,g,b)
        self.np.show()
Ejemplo n.º 3
0
BLACK = (0, 0, 0)
COLORS = (RED, YELLOW, GREEN, CYAN, BLUE, PURPLE, WHITE, BLACK)

# fill
for color in COLORS:
    neo.fill(color)
    neo.show()
    time.sleep(0.25)

# chase
for color in COLORS:
    for i in range(neo.n):
        neo[i] = color
        neo.show()
        time.sleep(0.025)

# rainbow
for i in range(255):
    neo.rainbow_cycle(i)
    neo.show()
    time.sleep(0.0025)

# rotate
for _ in range(neo.n * 3):
    neo.rotate(clockwise=True)
    neo.show()
    time.sleep(0.05)

neo.clear()
neo.show()
Ejemplo n.º 4
0
from microbit import *
from neopixel import NeoPixel

np = NeoPixel(pin0, 5)
np.clear()

pin1.set_analog_period_microseconds(3000)
pin2.set_analog_period_microseconds(3000)

fwd = 255
bck = 767
off = 511

state = 4

numactions = 4
action = 0


def forward(t):
    pin1.write_analog(fwd)
    pin2.write_analog(bck)
    sleep(t)
    pin1.write_digital(0)
    pin2.write_digital(0)


def backward(t):
    pin1.write_analog(bck)
    pin2.write_analog(fwd)
    sleep(t)
Ejemplo n.º 5
0
from microbit import *
from neopixel import NeoPixel

np = NeoPixel(pin0,5)
np.clear()

pin1.set_analog_period_microseconds(3000)
pin2.set_analog_period_microseconds(3000)

fwd = 255
bck = 767
off = 511

state = 4

numactions = 4
action = 0

def forward(t):
    pin1.write_analog(fwd)
    pin2.write_analog(bck)
    sleep(t)
    pin1.write_digital(0)
    pin2.write_digital(0)

def backward(t):
    pin1.write_analog(bck)
    pin2.write_analog(fwd)
    sleep(t)
    pin1.write_digital(0)
    pin2.write_digital(0)
Ejemplo n.º 6
0
from microbit import *
from neopixel import NeoPixel
# import music
import random

num_pixels = 50
foreground = [0xff, 0x00, 0x00]  # Hex color - red, green and blue
background = [0x10, 0x10, 0x10]
red = 0xf0
green = 0x00
blue = 0x00

ring = NeoPixel(pin2, num_pixels)
ring.clear()
data = []


def build_ranbow():
    #data.clear()
    for i in range(0, num_pixels):
        red, green, blue = 0, 0, 0
        shift = int(((i * 16) / num_pixels))
        if shift == 0:
            red = 0xff
        if shift > 0 and shift < 8:
            red = 0xff >> shift
            green = ((0xff << shift) >> 8) & 0xff
        if shift == 8:
            green = 0xff
        if shift > 8 and shift < 16:
            green = 0xff >> (shift - 8)