Rainbow light — Mini
The Mini has one big colour light (an RGB LED) that can make any colour you like by mixing red, green and blue. This program walks it through five colours, turns the whole thing dim, then switches it off — and starts again.
This is one project for both firmware versions: when MoBot opens it, the blocks write the code for the firmware of your Mini.
The program
Section titled “The program”Read the program as text
- MoBot Mini Start
- Print to serial
"Rainbow time!" - repeat forever
- Set RGB LED brightness to 60 %
- Print to serial
"red" - Set RGB LED to R 255 G 0 B 0
- wait 0.8 seconds
- Print to serial
"orange" - Set RGB LED to R 255 G 120 B 0
- wait 0.8 seconds
- Print to serial
"green" - Set RGB LED to R 0 G 255 B 0
- wait 0.8 seconds
- Print to serial
"blue" - Set RGB LED to R 0 G 0 B 255
- wait 0.8 seconds
- Print to serial
"pink" - Set RGB LED to R 255 G 0 B 200
- wait 0.8 seconds
- Print to serial
"going dim" - Set RGB LED brightness to 10 %
- wait 1.5 seconds
- Print to serial
"off" - Turn RGB LED off
- wait 1.5 seconds
What you need
Section titled “What you need”- A MoBot Mini, charged and switched on.
- A USB cable.
- Nothing to plug in. The colour light is on the board.
⚠️ First time? Read the “Before you send it” section of Blink and fade. A Mini straight out of the box does not run the program you send until it is set to Programmable.
How to run it
Section titled “How to run it”- Open 02-rainbow.mobot in MoBot.
- Plug the Mini in and choose its port.
- Press Send to Device.
- Watch the big colour light.
What you should see
Section titled “What you should see”The serial monitor names each colour just before it appears, so you can check the light with your eyes and the program with your reading:
| serial line | the light |
|---|---|
[MOBOT] red |
red |
[MOBOT] orange |
orange |
[MOBOT] green |
green |
[MOBOT] blue |
blue |
[MOBOT] pink |
pink |
[MOBOT] going dim |
still pink, but much fainter |
[MOBOT] off |
completely dark for a second and a half |
Then it all happens again.
The two moments that matter most are the last two. Going dim proves the brightness block works — the colour must stay pink and only get weaker. Off must be properly black, not “a bit dark”.
If a colour looks wrong — green where the program says red — the red, green and blue wires inside the light may be in a different order on your board. Say which colour appeared for which line; that is exactly the information a firmware fix needs.
The blocks
Section titled “The blocks”| block | what it does |
|---|---|
mobot_rgbsetcolor |
Mixes a colour. Each number is 0–255: how much red, how much green, how much blue. |
mobot_rgbbrightness |
How strong the light is, 0–100 %. Does not change the colour. |
mobot_rgboff |
Turns the colour light right off. |
mobot_print |
Says out loud which colour should be showing. |
The Python code
Section titled “The Python code”The same blocks write different Python for each firmware, and MoBot picks the one that fits the robot you use. The 2.x tab is for reference. This is a reading copy: editing it changes nothing, so change the blocks instead. The name map lists the names that changed.
# Rainbow light — mini (firmware 3.0)## This is what MoBot puts on a robot running firmware 3.0 as main.py when you open# 02-rainbow.mobot and press Send to Device. It is GENERATED from the blocks;# editing this file changes nothing. Edit the blocks instead.# The firmware 2.x version is 02-rainbow.main.py.
from machine import Pinimport time
print("[MOBOT]", 'Rainbow time!')while True: robot.rgb_led.set_brightness(60) print("[MOBOT]", 'red') robot.rgb_led.set_color(255, 0, 0) time.sleep(0.8) print("[MOBOT]", 'orange') robot.rgb_led.set_color(255, 120, 0) time.sleep(0.8) print("[MOBOT]", 'green') robot.rgb_led.set_color(0, 255, 0) time.sleep(0.8) print("[MOBOT]", 'blue') robot.rgb_led.set_color(0, 0, 255) time.sleep(0.8) print("[MOBOT]", 'pink') robot.rgb_led.set_color(255, 0, 200) time.sleep(0.8) print("[MOBOT]", 'going dim') robot.rgb_led.set_brightness(10) time.sleep(1.5) print("[MOBOT]", 'off') robot.rgb_led.off() time.sleep(1.5)# Rainbow light — mini## This is what MoBot puts on the board as main.py when you open# 02-rainbow.mobot and press Send to Device. It is GENERATED from the blocks;# editing this file changes nothing. Edit the blocks instead.
from machine import Pinimport time
print("[MOBOT]", 'Rainbow time!')while True: mobotMINI.rgb.set_brightness(60) print("[MOBOT]", 'red') mobotMINI.rgb.set_color(255, 0, 0) time.sleep(0.8) print("[MOBOT]", 'orange') mobotMINI.rgb.set_color(255, 120, 0) time.sleep(0.8) print("[MOBOT]", 'green') mobotMINI.rgb.set_color(0, 255, 0) time.sleep(0.8) print("[MOBOT]", 'blue') mobotMINI.rgb.set_color(0, 0, 255) time.sleep(0.8) print("[MOBOT]", 'pink') mobotMINI.rgb.set_color(255, 0, 200) time.sleep(0.8) print("[MOBOT]", 'going dim') mobotMINI.rgb.set_brightness(10) time.sleep(1.5) print("[MOBOT]", 'off') mobotMINI.rgb.off() time.sleep(1.5)Try changing it
Section titled “Try changing it”- Make your own colour:
R 255 G 255 B 0is yellow,R 128 G 0 B 255is purple,R 255 G 255 B 255is white. - Set brightness to 100 and look away — it is bright.
- Set every
waitto 0.1 and you get a disco.