Numbers on the 7-segment — Smart Home
The little red 3-digit display counts through four numbers, again and again: 1, then 22, then 333, then 0. One second each.
This is the first thing to try on a Smart Home board, because the display needs nothing plugged in and nothing set up — if these numbers appear, the board booted, your program was sent, and the display works.
This is one project for both firmware versions: when MoBot opens it, the blocks write the code for the firmware of your Smart Home.
The program
Section titled “The program”Read the program as text
- MoBot Start
- Print to serial
"7-segment test starting" - repeat forever
- Display Number 1 on 7-Segment
- wait 1 seconds
- Display Number 22 on 7-Segment
- wait 1 seconds
- Display Number 333 on 7-Segment
- wait 1 seconds
- Display Number 0 on 7-Segment
- wait 1 seconds
- Set digit 0 segments : a 1 b 0 c 0 d 1 e 0 f 0 g 1 dp 0
- wait 1 seconds
What you need
Section titled “What you need”- A Smart Home board (ESP32-S3) with the 3-digit 7-segment display on it.
- A USB cable.
How to run it
Section titled “How to run it”- Open 01-seven-segment.mobot in MoBot.
- Plug the board in and pick its port.
- Press Send to Device.
- Watch the red display.
What you should see
Section titled “What you should see”-
[MOBOT] 7-segment test startingappears once in the serial monitor. -
The red display then shows, one second apart, forever:
shows why 1one digit, pushed to the right 22two digits 333all three digits full 0back to the start -
On the fifth step the first digit (the left one) shows three bars, ≡, for one second. The other two digits keep what they showed before.
If the display stays dark but the serial line appeared, the program is running and the display is the problem. If nothing appears at all, the program did not reach the board.
The three-bars block
Section titled “The three-bars block”The last block in the loop is Set digit 0 segments : a 1 d 1 g 1. Each digit of the display is made of seven little bars, called a to g, and a dot, dp. Put 1 next to a letter to light that bar and 0 to leave it dark.
Here a is the top bar, g the middle one and d the bottom one, so the first digit draws three horizontal bars, like this: ≡.
The block above it, Display Number on 7-Segment, is the easy way to show a number. Use Set digit … segments when you want to draw something that is not a number.
The blocks
Section titled “The blocks”| block | what it does |
|---|---|
iot_print |
Sends a line to the serial monitor. |
repeat_forever |
Everything inside runs over and over. |
iot_7segvar |
Shows a whole number on the 3-digit display. |
wait |
Pauses, in seconds. |
iot_7seg |
Lights chosen segments of one digit. |
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.
# Numbers on the 7-segment — iot (firmware 3.0)## This is what MoBot puts on a robot running firmware 3.0 as main.py when you open# 01-seven-segment.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-seven-segment.main.py.
from machine import Pinimport time
print("[MOBOT]", '7-segment test starting')while True: home.number_display.show_number(1) time.sleep(1) home.number_display.show_number(22) time.sleep(1) home.number_display.show_number(333) time.sleep(1) home.number_display.show_number(0) time.sleep(1) home.number_display.set_digit(0, ['A', 'D', 'G', ]) time.sleep(1)# Numbers on the 7-segment — iot## This is what MoBot puts on the board as main.py when you open# 01-seven-segment.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]", '7-segment test starting')while True: mobotIOT.seg.number(1) time.sleep(1) mobotIOT.seg.number(22) time.sleep(1) mobotIOT.seg.number(333) time.sleep(1) mobotIOT.seg.number(0) time.sleep(1) mobotIOT.seg.set_segments_for_digit(0, ['A', 'D', 'G', ]) time.sleep(1)Try changing it
Section titled “Try changing it”- Change 333 to your age.
- Make the waits 0.2 and watch the numbers race.
- Try 1234 in one of the Display Number blocks. The display only has three digits, so it cannot show four — a good thing to discover on purpose.