Skip to content

Search the documentation

Kit
Firmware

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 blocks of this example, from top to bottom.
Click the picture to view it larger.Open full sizeThe same program written as Python is further down this page, in The Python code.
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
  • 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.

  1. Open 02-rainbow.mobot in MoBot.
  2. Plug the Mini in and choose its port.
  3. Press Send to Device.
  4. Watch the big colour light.

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.

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 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.

02-rainbow.firmware-3.main.py
# 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 Pin
import 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)
  • Make your own colour: R 255 G 255 B 0 is yellow, R 128 G 0 B 255 is purple, R 255 G 255 B 255 is white.
  • Set brightness to 100 and look away — it is bright.
  • Set every wait to 0.1 and you get a disco.