HomeTurtlegraficsGPanelRobotics WebTigerPython
 Python - Online
RGBleds
Deutsch   English   

9. RGB LEDS (only CallMk)

 

 

YOU LEARN HERE...

 

how to switch on the four RGB LEDs on the CalliMk board in different colours.

 

 

EXAMPLES

 

Example 1: Switching RGB LEDs on and off

In addition to the two red LEDs at the front, the CalliMk also has four LEDs at the bottom of the chassis.

With the command rgbLED(r, g, b), where r, g, b are the three colour components (red, green, blue), the four RGB LEDs are switched on. You can select integers between 0 and 255 for r, g, b.
The LEDs are switched off with rgbLED(0, 0, 0) .

 

Program:

from callimk import *

rgbLED(200, 0, 0)
delay(2000)
rgbLED(0, 200, 0)
delay(2000)
rgbLED(0, 0, 200)
delay(2000)
rgbLED(255, 0, 255)
delay(2000)
rgbLED(0, 0, 0)
► Copy to clipboard

 

Example 2: Changing the colour intensity
The LEDs light up green, first weakly, then increasingly stronger. The green colour component g is 10 at the beginning and is increased by10 after every second. After g has reached the maximum value of 255, the LEDs briefly light up red and are then switched off.

 


Program:

from callimk import *

g = 10
while g <= 255: 
    rgbLED(0, g, 0)
    delay(1000)
    g += 10
rgbLED(255, 0, 0)
delay(1000)
rgbLED(0, 0, 0)
Copy to clipboard

 

Example 3: Illuminating the roadway
While the robot is travelling on a left-hand bend, the roadway is illuminated in red; when travelling on a right-hand bend, it is illuminated in green.

 


Program:

from callimk import *

repeat 2:
    rgbLED(255, 0, 0)
    leftArc(0.2)
    delay(5000)
    rgbLED(0, 255, 0)
    rightArc(0.2)
    delay(5000)
stop()    
rgbLED(0, 0, 0)
Copy to clipboard

 

 

REMEMBER...

 

With the command rgbLED(r, g, b), where r, g, b are numbers between 0 and 255, the four RGB LEDs are switched on and remain lit until another colour is switched on or the LEDs are switched off with the command rgbLEDs(0, 0, 0).

 

 

TO SOLVE BY YOURSELF

 

 


1.


Experiment with different colours. Which colour components do you have to choose so that the LEDs are
a) yellow
b) cyan
c) violet
d) white
light up?

2. The robot measures the distance to the obstacle with its ultrasonic sensor. If the distance is less than 25, the LEDs light up red. As soon as the object is at a greater distance, the LEDs light up green.

3.

The robot first moves forwards for 2 seconds, stops for 1 second, moves backwards for 2 seconds and stops again for 1 second. It repeats this movement three times. The LEDs light up green when travelling forwards, yellow when stopping and red when reversing.