Deutsch English |
YOU LEARN HERE... |
how colors are made up of a red, a green and a blue component and how to light up the color LEDs with the desired color. |
RGB-LED |
To save and process color images with the computer, the colors must be defined as numbers. There are several ways to do this. The best known is the RGB color model, where the intensities of the three color components red, green and blue are specified as numbers between 0 and 255.
|
|
EXAMPLES |
Program: from calliope_mini import * led.set_colors(255, 0, 0) sleep(1000) led.set_colors(0, 255, 0) sleep(1000) led.set_colors(0, 0, 255) sleep(1000) led.set_colors(255, 255, 0) sleep(1000) led.set_colors(255, 0, 255) sleep(1000) led.set_colors(0, 255, 255) sleep(1000) led.set_colors(0, 0, 0) For Calliope_mini 3 you have to adapt the program accordingly. Here the first LED lights up red, the second green and the third light blue. Program: from calliope_mini import * from neopixel import * LEDs = NeoPixel(pin_RGB, 3) LEDs[0] = (255,0,0) LEDs[1] = (0,255,0) LEDs[2] = (0,255,255) LEDs.show() If the maximum possible number 255 is selected for the color component, the LEDs light up very brightly. It is more pleasant if you choose smaller numbers for r, g, b: LEDs[0] = (100,0,0) LEDs[1] = (0,100,0) LEDs[2] = (0,100,100) Example 2: Lighting up the color LED in randomly selected colors
Program: from calliope_mini import * from random import randint def randomColor(): r = randint(0, 100) g = randint(0, 100) b = randint(0, 100) led.set_colors(r, g, b) while not button_a.was_pressed(): randomColor() sleep(500) led.set_color(0, 0, 0) Example 3: Using a color LED for a voltage display
Program: from calliope_mini import * while True: if pin1.read_analog() > 400: led.set_colors(0, 255, 0) elif pin2.read_analog() > 400: led.set_colors(255, 0, 0) else: led.set_colors(0, 0, 255) sleep(100) |
REMEMBER ... |
The color of a color LED is determined by the red, green and blue color components (a number between 0 and 255). As the LED shines very brightly, it is better to use numbers between 0 and 100. |
TO SOLVE BY YOURSELF |
|