Skip to content

Search the documentation

Kit
Firmware

Blink and fade — Mini

Start here. This is the smallest program that proves your Mini is alive. LED 1 blinks on and off. LED 2 does something LED 1 cannot: it goes bright, then half, then very dim, then off — because it is dimmed with a brightness number instead of just switched.

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 "Hello from MoBot Mini!"
  • repeat forever
    • Set LED 1 ON
    • wait 0.3 seconds
    • Set LED 1 OFF
    • wait 0.3 seconds
    • Set LED 2 to 100 %
    • wait 0.3 seconds
    • Set LED 2 to 40 %
    • wait 0.3 seconds
    • Set LED 2 to 5 %
    • wait 0.3 seconds
    • Set LED 2 to 0 %
    • wait 0.3 seconds
  • A MoBot Mini, charged and switched on.
  • A USB cable.
  • Nothing to plug in. Both lights are already on the board.

Before you send it — set the Mini to Programmable

Section titled “Before you send it — set the Mini to Programmable”

⚠️ A brand-new Mini does not run the program you send. The Mini starts in Manual driving, the mode the phone app drives, and your program only runs while the robot’s mode is Programmable.

Set it once, in either of two ways, and every example in this folder will work afterwards. The Mini keeps its mode, even when it is switched off.

From the computer. Press Send to Device. If the Mini is in another mode, MoBot asks: “The robot is in Manual driving. Switch it to Programmable to run your program?” Answer Switch to Programmable. (If you answer Keep Manual driving, MoBot saves your program but does not run it.)

From the phone. Open the MoBot app, connect to the Mini and tap the Programmable tile. The home screen then says Robot mode: Programmable.

If MoBot says the robot did not answer, choose Programmable in the MoBot app and try again. If the app has no Programmable tile, update the app. Your program stays on the robot. To drive from the phone again, tap another tile.

  1. Open 01-blink.mobot in MoBot.
  2. Plug the Mini in and choose its port.
  3. Press Send to Device.
  4. Watch the two little lights on the board.
  • [MOBOT] Hello from MoBot Mini! appears once in the serial monitor.
  • LED 1 blinks: on for a third of a second, off for a third of a second.
  • LED 2 then goes bright → half → almost off → off, and the whole thing starts again.

The two lights take turns, so the board looks like it is breathing.

If the serial line appears but no light moves, the program ran and the LEDs are the problem. If nothing at all appears, the Mini is probably still in Manual mode — go back to “Before you send it”.

block what it does
program_start Every MoBot program starts here.
mobot_print Sends a line to the serial monitor. Proof the program really started.
repeat_forever Everything inside runs again and again.
mobot_ledon Turns LED 1 fully on or fully off.
mobot_ledbright Sets a light to a percentage — 100 is bright, 5 is a whisper, 0 is off.
wait Pauses. Make it 2 and the blink gets slow and sleepy.

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.

01-blink.firmware-3.main.py
# Blink and fade — mini (firmware 3.0)
#
# This is what MoBot puts on a robot running firmware 3.0 as main.py when you open
# 01-blink.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 01-blink.main.py.
from machine import Pin
import time
print("[MOBOT]", 'Hello from MoBot Mini!')
while True:
robot.led1.set(1)
time.sleep(0.3)
robot.led1.set(0)
time.sleep(0.3)
robot.led2.set_brightness(100)
time.sleep(0.3)
robot.led2.set_brightness(40)
time.sleep(0.3)
robot.led2.set_brightness(5)
time.sleep(0.3)
robot.led2.set_brightness(0)
time.sleep(0.3)
  • Make every wait 0.05. The lights flicker like a firefly.
  • Change Set LED 2 to 5 % to 50 % and see if you can still tell the difference from 40 %.
  • Swap Set LED 1 to LED 2 and watch the two blocks fight over the same light.