LED Show
Now we add some algorithms in this chapter to make the LED display more styles. You can take this as a
reference, then you can use your imagination to write your own algorithm to achieve the LED styles you want.
Run Program
If the terminal displays the directory as below, you can directly run the Led.py.
1.If not, execute the cd command:
cd ~/Freenove_4WD_Smart_Car_Kit_for_Raspberry_Pi/Code/Server
2.Run Led.py:
sudo python Led.py
You can press "Ctrl + C" to end the program.
Part of code is as below:
# -*-coding: utf-8 -*-
import time
from rpi_ws281x import *
# LED strip configuration:
LED_COUNT = 8 # Number of LED pixels.
LED_PIN = 18 # GPIO pin connected to the pixels (18 uses PWM!).
LED_FREQ_HZ = 800000 # LED signal frequency in hertz (usually 800khz)
LED_DMA = 10 # DMA channel to use for generating signal (try 10)
LED_BRIGHTNESS = 255 # Set to 0 for darkest and 255 for brightest
LED_INVERT = False # True to invert the signal (when using NPN transistor level shift)
LED_CHANNEL = 0 # set to '1' for GPIOs 13, 19, 41, 45 or 53
# Define functions which animate LEDs in various ways.
class Led:
def __init__(self):
self.ORDER = "GRB" #Control the sending order of color data
# Create NeoPixel object with appropriate configuration.
self.strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT,
LED_BRIGHTNESS, LED_CHANNEL)