Blink the LED — Smart Car
The “hello world” of MoBot. LED 1 on the Smart Car turns on for half a second, off for half a second, and keeps going until you switch the robot off.
This is one project for both firmware versions: when MoBot opens it, the blocks write the code for the firmware of your Smart Car.
The program
Section titled “The program”Read the program as text
- MoBot Start
- Print to serial
"Blink!" - repeat forever
- Set LED 1 ON
- wait 0.5 seconds
- Set LED 1 OFF
- wait 0.5 seconds
What you need
Section titled “What you need”- A Smart Car, charged and switched on.
- A USB cable.
How to run it
Section titled “How to run it”- Open 01-blink.mobot in MoBot (double-click it, or use Open in the IDE).
- Plug the robot in and pick its port.
- Press Send to Device. MoBot sends the program to the robot and starts it.
- Watch LED 1.
What you should see and hear
Section titled “What you should see and hear”[MOBOT] Blink!appears once in the serial monitor, right after the program starts.- LED 1 blinks steadily: on half a second, off half a second.
- It never stops. Press Stop, or send a different program, to end it.
If the LED does not blink but the serial line appeared, the program is running and the LED is the problem — check that you are looking at LED 1 and not LED 2. If nothing appears at all, the program did not reach the robot.
The blocks
Section titled “The blocks”| block | what it does |
|---|---|
program_start |
Every MoBot program starts here. |
mobot_print |
Sends a line to the serial monitor, so you can tell the program really started. |
repeat_forever |
Everything inside runs over and over. |
mobot_ledon |
Turns LED 1 on (ON) or off (OFF). |
wait |
Pauses. Change the 0.5 to 2 and the blink gets slow and lazy. |
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.
# Blink the LED — robotics (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 Pinimport time
print("[MOBOT]", 'Blink!')while True: robot.led1.set(1) time.sleep(0.5) robot.led1.set(0) time.sleep(0.5)# Blink the LED — robotics## This is what MoBot puts on the board 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.
from machine import Pinimport time
print("[MOBOT]", 'Blink!')while True: mobotROBOTICS.led1.setState(1) time.sleep(0.5) mobotROBOTICS.led1.setState(0) time.sleep(0.5)Try changing it
Section titled “Try changing it”- Make the wait 0.1 — the LED flickers.
- Set the second
Set LEDblock to LED 2 instead of LED 1, and watch the two LEDs take turns.