| Deutsch English |
![]()
WHAT ARE NEOPIXELS? |
In the near future, there will only be bulbs made up of LEDs. A LED is a semiconductor diode that converts the electrical current into light with high efficiency. Depending on the material of the LED, different colors are emitted. If you combine a red, green and blue LED in a housing, the result is a color LED that can be used to create any other color through additive color mixing. The principle is also applied to color television. |
PROGRAMMING WITH A BIG FUN FACTOR |
A lighting system controlled by a microcontroller such as the micro:bit is extremely flexible and versatile. When writing the control program you can fully exercise your imagination. In this worksheet, you will learn about some basic procedures that helps you for your own project. The programming of lighting systems is also fun, because the effects of each line of code are immediately visible. |
INTERFACING |
|
EXERCISE 1: SET COLOR OF PIXELS |
To control the neopixels with one data line only, a serial protocol is used. In a sequence the 3 color values for the first pixel, then for the second, etc. are sent. The first pixel "snaps off" its three color values and forwards the remainder of the data stream. Under MicroPython, programming is very simple, as explained here: After importing the module neopixel, create an object NeoPixel by specifying which data port is (usually P0) and how many neopixels your arrangement has, so for 24 LEDs attached to P0 (np is any variable name): The storage system now produces a list of 24 tuples that stores the RGB colors of the 24 LEDs (as (R, G, B) color values each in the range 0..255). The list index corresponds to the position of the LED (in a sequence depending on the wiring of the LED arrangement).
As you can see, besides the module microbit you also have to import the module neopixel. If you forget the np.show(), you don't see any change in the colors, since your LEDs will not receive the data stream. |
EXERCISE 2: LET A PIXEL RUN |
|
EXERCISE 3: GROWING COLORED WORM |
|
EXERCISE 4: CONTROL ALL LEDs TOGETHER |
|
EXERCISE 5: FLICKERING CANDLES |
|
EXERCISE 6: REALIZE YOUR OWN IDEAS |
Create your own funny light show.
|