Home bpi:bit bpi:bit RGB led examples in MicroPython

bpi:bit RGB led examples in MicroPython

by shedboy71

As mentioned in a previous article we said that the bpi:bit has 25 RGB leds fitted to it, you can see these in the image below

This is a basic example which displays a message similar to the micro:bit can,.

[codesyntax lang=”python”]

from microbit import *
display.scroll("Hello")

[/codesyntax]

It as also easy to change the color of the LED. There are 8 preset  colors which are built into the firmware, these are as follows with the actual values that are used

black = [0, 0, 0]
Red = [2, 0, 0]
Orange = [2, 1, 0]
Yellow = [2, 2, 0]
Green = [0, 2, 0]
Blue = [0, 0, 2]
Indigo = [0, 2, 2]
Purple = [2, 0, 2]

Here is an example which will now display the same message as before but this time its an orange color

[codesyntax lang=”python”]

from display import*
display=Display()
display.scroll("Hello",Orange)

[/codesyntax]

You can also create custom colors by entering parameters for the RGB values, for example 1,0,0 will be a fairly dim red colors. You can increase the value up to 255 which increases the brightness do 255, 0, 0 is the brightest red you can get.

The ability to change these values from 0 to 255 is where the RGB LED’s get the total number of available colors from.

So this would be 256 * 256 * 256=16777216 colors

[codesyntax lang=”python”]

from display import*
display=Display()
mycolor=[1,53,21]
display.scroll("hello",mycolor)

[/codesyntax]

I usually keep the values quite low, the higher the value as stated means that the LEDs can be very bright and you should be very careful and not look at the LED

You may also like

Leave a Comment