Example #1
0
num_pixels = 64  # Number of pixels driven from Crickit NeoPixel terminal

# The following line sets up a NeoPixel strip on Seesaw pin 20 for Feather
pixelss = NeoPixel(crickit.seesaw, 20, num_pixels, brightness=0.05)

RED = (255, 0, 0)
YELLOW = (255, 255, 0)
GREEN = (0, 255, 0)
CYAN = (0, 255, 255)
BLUE = (0, 0, 255)
PURPLE = (180, 0, 255)
ORANGE = (255, 125, 0)

#for i in range(1, 3):
pixelss.fill(PURPLE)
pixelss.show()
#print(i)
#time.sleep(1)

a = 0

# Create one continuous servo on crickit servo port #1
left_wheel = crickit.dc_motor_1
# Create one continuous servo on crickit servo port #2
right_wheel = crickit.dc_motor_2

holder = amg.pixels
#print(holder)

while True:
    holder = amg.pixels
Example #2
0
class MyNeoPixels:
    def __init__(self,
                 n,
                 seesaw=crickit.seesaw,
                 pin=20,
                 bpp=3,
                 brightness=1.0,
                 auto_write=True,
                 pixel_order=None):
        self.numPixels = n
        self.pixels = NeoPixel(
            seesaw, pin, n,
            auto_write=False)  #, bpp, brightness, auto_write, pixel_order)
        self.pixels.brightness = 0.5

    def setPixelColor(self, idx, color):
        self.pixels[idx] = color

    def show(self):
        self.pixels.show()
        return

    def fill(self, color):
        self.pixels.fill(color)

    # Define functions which animate LEDs in various ways.
    def colorWipe(self, color, wait_ms=50):
        """Wipe color across display a pixel at a time."""
        for i in range(self.numPixels):
            self.setPixelColor(i, color)
            self.show()
            time.sleep(wait_ms / 1000.0)

    def theaterChase(self, color, wait_ms=50, iterations=10):
        """Movie theater light style chaser animation."""
        for j in range(iterations):
            for q in range(3):
                for i in range(0, self.numPixels, 3):
                    self.setPixelColor(i + q, color)
                self.show()
                time.sleep(wait_ms / 1000.0)
                for i in range(0, self.numPixels, 3):
                    self.setPixelColor(i + q, 0)

    def rainbow(self, wait_ms=20, iterations=1):
        """Draw rainbow that fades across all pixels at once."""
        for j in range(256 * iterations):
            for i in range(self.numPixels):
                self.setPixelColor(i, wheel((i + j) & 255))
            self.show()
            time.sleep(wait_ms / 1000.0)

    def rainbowCycle(self, wait_ms=20, iterations=5):
        """Draw rainbow that uniformly distributes itself across all pixels."""
        for j in range(256 * iterations):
            for i in range(self.numPixels):
                self.setPixelColor(
                    i, wheel((int(i * 256 / self.numPixels) + j) & 255))
            self.show()
            time.sleep(wait_ms / 1000.0)

    def theaterChaseRainbow(self, wait_ms=50):
        """Rainbow movie theater light style chaser animation."""
        for j in range(256):
            for q in range(3):
                for i in range(0, self.numPixels, 3):
                    self.setPixelColor(i + q, wheel((i + j) % 255))
                self.show()
                time.sleep(wait_ms / 1000.0)
                for i in range(0, self.numPixels, 3):
                    self.setPixelColor(i + q, 0)

    def set_neopixels(self, color, count):
        if count > self.numPixels:
            count = self.numPixels
        logging.info("setting %d pixesl to %s" % (count, color))
        for i in range(0, self.numPixels):
            if i < count:
                self.setPixelColor(i, color)
            else:
                self.setPixelColor(i, colors['off'])
        self.show()

    # health will be a setting of 10 pixels, and the number will be out of 100
    def health(self, color, health, tip='off', wait_ms=50):
        self.set_neopixels(color, health)
        time.sleep(0.002)
        self.setPixelColor(self.numPixels - 1, colors[tip])
        self.show()

    ##############
    operations = {
        # custom = has A, B, C, D
        #'magic_item': magic_item,
        # needs colour and count
        'set': set_neopixels,
        'health': health,
        #needs colour
        'colourwipe': colorWipe,
        'theatrechase': theaterChase,
        #no colour option
        'rainbow': rainbow,
        'rainbow_cycle': rainbowCycle,
    }

    ###############
    def play(self, payload={}):
        operationname = get(payload, 'operation', 'colourwipe')
        operation = get(MyNeoPixels.operations, operationname,
                        MyNeoPixels.operations['colourwipe'])
        logging.info("playing %s" % operationname)

        if operationname == 'magic_item':
            operation(self, payload)
            return

        if operationname == 'rainbow' or operationname == 'rainbow_cycle':
            operation(self)
            return

        colourname = get(payload, 'colour', 'off')
        colour = get(colors, colourname, colors['off'])
        # TODO: maybe change to using HTML colors #000000 style?
        if operationname == 'colourwipe' or operationname == 'theatrechase':
            operation(self, colour)
            return

        count = get(payload, 'count', 10)
        operation(self, colour, count)