Infineon Team
Published © MIT

Controlling NeoPixels with Micropython

Light up your world with the magic of Neopixel lights using Infineon's PSoC6 board with Micropython!

BeginnerProtip2 hours319

Things used in this project

Hardware components

CY8CPROTO-062-4343W
Infineon CY8CPROTO-062-4343W
×1
Adafruit High Density Neopixel Stick
×1
Adafruit NeoPixel Digital RGB LED Strip 144 LED, 1m White
Adafruit NeoPixel Digital RGB LED Strip 144 LED, 1m White
×1

Software apps and online services

MicroPython
MicroPython
Thonny

Story

Read more

Schematics

Schematic

Code

Neopixel

MicroPython
from machine import Pin, bitstream
import time

# Define the timing for the bitstream based on the LED's datasheet
timing = [500, 1125, 800, 750]

# Set up the data pin for the LEDs
DIN1 = Pin('P9_1', Pin.OUT, value=0)

def manualLightAll(buf):
    bitstream(DIN1, 0, timing, buf)

def create_color(red, green, blue):
    return bytearray([red, green, blue])

def animation_cycle(amount, cycles, delay):
    for cycle in range(cycles):  # Number of cycles of the animation
        for i in range(amount):  # Amount of LEDs
            buf = bytearray()
            # Create a color pattern that will cycle through each LED
            for j in range(amount):
                if j == i:
                    # Red color
                    buf.extend(create_color(255, 0, 0))
                elif j == (i + 1) % amount:
                    # Green color
                    buf.extend(create_color(0, 255, 0))
                elif j == (i + 2) % amount:
                    # Blue color
                    buf.extend(create_color(0, 0, 255))
                else:
                    # Turn off the LED if not in use
                    buf.extend(create_color(0, 0, 0))
            manualLightAll(buf)
            time.sleep(delay)  # Delay between each frame

# Run the animation
amount_of_leds = 8         # Number of LEDs in your strip
animation_cycles = 20       # How many times the animation should run
frame_delay = 0.1          # Delay between each color change in seconds

animation_cycle(amount_of_leds, animation_cycles, frame_delay)

Credits

Infineon Team

Infineon Team

84 projects • 128 followers

Comments