Band 7 · Distance and Display
Swap The guard on a four-digit display
The same parking guard, two pins instead of six, a much shorter sketch, and digits you can read across a room.
Sketches for this project
Every file opens with a plain-English header saying what it does and how to wire it, hole by hole.
The other road through Band 7
Band 7's core build puts the parking guard on an LCD. On the bare sixteen-pin kind that is twelve wires and a contrast knob, and it is the longest single build in the course.
This is the same device on a four-digit display. Two Arduino pins instead of six, and four wires to the screen instead of twelve. Twelve wires on the whole board rather than twenty-two. And digits bright enough to read from across a room, which is a thing an LCD genuinely cannot do.
If the twelve-wire screen defeated you, come here instead. Be honest with yourself about the trade, though. You do not get the padding bug, you do not get the contrast knob, you do not get the experience of finding one wrong wire among twelve, and you do not get the sixteen-character writing exercise, which is the best design problem in the band and cannot be done on four digits. Those are real losses. The Look closer section turns two of them into something you can write up, and the Done list below makes you do the writing exercise on paper anyway.
Is this your display?
Marked CLK, DIO, VCC, GND. There is a chip on the back doing the hard work.
→ This page. Build it.
That is the LCD, the bare kind, with nothing soldered to its back. It shows letters as well as numbers, which this one cannot. Twelve wires and a contrast knob.
→ Band 7 Part 6b, and b7_05_bin_worked_parallel.ino.
Four pins on that little board, marked GND VCC SDA SCL. That is the I²C LCD: the same screen with the twelve wires already done for you inside. Four wires, no contrast knob.
→ Band 7 Part 6a. Do that rather than this page: it is already short, and you keep the letters.
If you have both, build this one first. It gets you a working guard in an hour, and the LCD version then makes much more sense because you already know what the device is supposed to do.
Four wires to the screen, twelve on the board
30 minj. The buzzer sits down in rows a and b and its wire still runs the long way round to the top pair. Split the rail wires across both pairs and nothing works, with nothing visibly wrong.VCC goes to the + rail instead of straight to 5V, its GND goes to the − rail instead of straight to a GND pin, and its Echo goes back to pin 11 if Part 6b had you move it to pin 9. The table below has both.Install the library. Tools, then Manage Libraries, search TM1637, and install the one by Avishay Orpaz. Once, on one machine.
Wire it.
| Part | Pin | Note |
|---|---|---|
Display CLK | 2 | Any digital pin would do; these two were free. |
Display DIO | 3 | |
Display VCC | + rail | Two things want 5V and the Arduino has one 5V pin. That is what the + rail is for. |
Display GND | − rail | |
Sensor VCC | + rail | |
Sensor Trig | 10 | |
Sensor Echo | 11 | Move it back to 11 if you got as far as Part 6b, which had you put it on pin 9 because the LCD wanted pin 11 for itself. This display does not. Leaving it on 9 gives you a permanent 999 that looks exactly like a broken sensor. |
Sensor GND | − rail | |
| Buzzer | 6 | Body in the board, long leg b40, short leg b42. Wire a40 to pin 6, wire a42 to the − rail. No resistor. If the legs will not reach two holes apart, use b40 and b43, and move the − rail wire to a43. Never put both legs in the same numbered column: the five holes in a column are one connection, so the buzzer would be shorted out and pin 6 joined straight to ground. |
| Power | 5V | One wire from the + rail to the Arduino's 5V pin |
| Ground | GND | One wire from the − rail to a GND pin |
Upload b7_06_guard_tm1637.ino.
VCC and GND first. Unlike an LCD there is no contrast to get wrong, so a dark display here really is a power problem.CLK and DIO are swapped. They are next to each other on the board and it is an easy mistake.5 in screen.setBrightness(5). It goes from 0 to 7.A whole class of bug that is simply not available here
25 minBand 7 Part 7 spends a long time on two faults: a screen that flickers, and a screen that leaves old digits behind when the number gets shorter. Going from 100 to 99 showed 990, and the fix was to pad every write to a fixed width.
Neither problem exists on this display.
void showDistance(long cm) {
if (cm == lastShown) {
return;
}
lastShown = cm;
screen.showNumberDec(cm, false);
}
No padding. No spaces. No counting to sixteen. showNumberDec draws all four digits every time, so there is nothing left over to leave behind.
The question worth sitting with
Two devices doing the same job, and one of them has a whole category of bug that the other cannot have.
- Why can the TM1637 not leave an old digit behind, when the LCD can?
- These three lines are still there even though flickering is not a problem here:
Take them out and upload. What actually changes?if (cm == lastShown) { return; } - Which of the two devices would you rather hand to somebody who has never programmed?
Check your answers
1. Because it has no cursor and no idea of “where you are”. An LCD writes characters one after another from wherever the cursor was left, so a short word overwrites part of a long one. The TM1637 has exactly four digit positions and redraws all of them on every call. Fewer choices, fewer mistakes.
2. Very little that you can see, and that is the honest answer. Taking it out makes the board send the same number to the display about twenty times a second, which is the rate the delay(50) at the bottom of loop sets, instead of only when the number changes: wasteful, and on some displays a source of faint flicker, but not visibly broken here. Keeping it is still right. Doing work that changes nothing is a habit worth not having, and on a busier sketch it would matter.
3. There is no wrong answer, but say why. This one is easier to wire, easier to write for, and readable across a room. The LCD shows words, which is the entire reason Band 7's core build says Nearly there rather than a number. A guard that can say STOP is telling somebody what to do; one that says 08 is making them work it out.
The colon, and the two numbers that are easy to confuse
The two dots in the middle live on the second digit, and there are two ways to switch them on. They use different numbers, and swapping them is the usual way people lose an evening.
| If you are using | The colon is | Looks like |
|---|---|---|
setSegments, drawing digits by hand | 0x80, added into the second digit's own byte | data[1] = data[1] | 0x80; |
showNumberDecEx, letting the library do it | 0x40, passed as the dots argument | screen.showNumberDecEx(t, 0x40); |
0x80 is the colon bit inside a digit. 0x40 is what showNumberDecEx wants you to hand it, and the library turns it into 0x80 on your behalf. Two numbers for one job, because two different people wrote the two functions. This is normal, and reading the library's own header file is how you settle arguments like this.
This sketch leaves the colon off. Turn it on with showNumberDecEx(cm, 0x40) if you want to see it. Blinking it once a second is what makes a four-digit display look like a clock rather than a number, and it is a few lines with a millis check if you ever build one.
Make it yours
35 min- Bronze
- Show
----instead of999when nothing is in range. UsesetSegments, which takes four bytes, one for each digit:uint8_t dashes[] = {0x40, 0x40, 0x40, 0x40};screen.setSegments(dashes);
In asetSegmentsbyte,0x40is the middle bar of a digit. That is the same number that means “colon” when you hand it toshowNumberDecEx, and it is exactly the confusion the table above is about. Then say in your log, in one sentence, why dashes are better than999for the person using the thing. - Silver
- Use the four digits to show two numbers at once: the current distance on the left pair and the closest you have got on the right pair, with the colon lit to separate them. You have four digits and two things to say, so both have to fit in two digits each, and deciding what to do about 100 or more is the interesting part.
- Gold
- Make the brightness follow the room, using the light sensor from Band 4: dim at night, bright in daylight. Then measure your own thresholds properly, as Band 4 taught you, and write them in your log. A display that is blinding at night is a display people unplug.
You still owe Band 7 the same evidence
This Swap replaces the LCD guard. To claim Band 7 you still need:
- A video of somebody using it, and a close photo of the display with a real reading on it
- Your ruler-accuracy table from Part 3, all five rows, plus your notes on the three awkward surfaces
- Your beep timing table from Part 9b. Part 9b walks through the LCD sketch, but its
gapForfunction is character for character the same as the one in your sketch, so do the table on your own file and write in your log that you did - Your four sixteen-character messages, written out and counted on paper, even though this display cannot show them. This is the band's best design exercise and you do not get to skip it for having a shorter screen
- The two distances you decided you would trust, and why
- Your build log
- Five or six correct answers in Part 11, the Check yourself questions, including question 2
Part 11's questions are set on an LCD sketch you have not built, and one of them is about the padding problem this display does not have. Answer them anyway, and use the comparison above to do it. Knowing why a bug cannot happen on your hardware is a better answer than never having met it.
Ship it
One video under sixty seconds, and one post of five lines. You built something different from the person next to you, so your video is the one nobody else in the room can post. Say in the post which build you chose and why — that choice is itself worth a line.
The four shots: three seconds of the thing still, fifteen of you doing something to it, fifteen of it responding all the way to the end, and ten of your measurement or the thing that went wrong first.
Show your work has the template and the three checks to
make before anything goes public. Tag it #BozomaBuilds.