Band 3 · Combination Lock
Practice The toggle lamp, from nothing
One button, one lamp, press to toggle. You did it in Band 3 with the code in front of you. Do it again with nothing in front of you.
Sketches for this project
Every file opens with a plain-English header saying what it does and how to wire it, hole by hole.
One button, one lamp, press to toggle
The smallest useful device there is. Press once, light on. Press again, light off. It should work a hundred times out of a hundred.
You did this in Band 3 with the band's code in front of you. Do it again with nothing in front of you, and find out how much of it you actually own.
Why the smallest job is a good one to repeat
There is exactly one hard idea in it and no wiring to hide behind. If your toggle is unreliable you cannot blame the circuit, because the circuit is a button and a light.
The hard idea is that a button that is held down is down for thousands of rounds of loop, and a toggle that reacts to down instead of the moment it goes down will flip thousands of times and land wherever it likes.
Build it, then measure whether it works
25 minSo move the button along: columns 25 and 27, wired exactly the way Band 3 Part 3 does it at 1 and 3. Legs in
f25, f27, e25, e27. Wire j25 to pin 2, and a27 to the − rail.Count the wires on that rail before you power up: the button's, the light's, and one from the rail to a GND pin. That last one is Band 1's, it is the one people forget when they rebuild, and without it the rail is dead metal.
And use the top − rail for everything, the one nearest row
j, because that is the one Band 1 uses. Band 3 used the bottom one. On most boards the two are not joined, so the button's ground wire is a long one running the length of the board. Run it rather than reaching for the near rail.Write it from scratch. Do not open Band 3's sketch until you have something that runs.
The check is a count, not a feeling
“It seems to work” is how a bouncy button gets shipped. So count.
- Press it twenty times, deliberately, pausing between each. Count out loud.
- The light should have changed state twenty times, so it ends up back where it started.
Then make the test tell you more than that. Counting only whether it ends up right catches an odd number of extra presses and misses an even number, which is roughly half of real bounce. Add a running count with Serial.println and read the last number. It should say 20. Serial is Band 3 Part 3.
The two things it needs, if you are stuck
One. A variable holding what the button read last time round, so you can tell the difference between “it is down” and “it has just gone down”.
Two. A short wait after you notice a change, so the mechanical clatter inside the switch has finished before you look again. Twenty to fifty thousandths of a second is plenty.
Band 3 Parts 8 and 9 are where both of those come from. Read them again rather than copying the sketch.
Two ways further
- Bronze
- Make the lamp fade on and off over half a second instead of snapping, using Band 2's
analogWrite. Move the light to a~pin first. Then notice that the button stops responding during the fade, and say why in one sentence. That sentence is Band 5 arriving. - Silver
- Add a second button that does not toggle but always turns it off, however the lamp got on. Two inputs, one state, and now you have to think about what happens when both are pressed together.
Keep
- Your count out of twenty, before and after adding the debounce
- Your code, written without looking at the band's
- One sentence on the difference between “the button is down” and “the button has just gone down”
Ship it
This one is yours. Nobody handed you a sketch for it, so the code in your video is code you wrote. Say that in the post, because it is the difference between somebody who can follow a tutorial and somebody who can build a thing, and it is the difference an employer is looking for.
The four shots as usual, and make the fourth one count: the check this page asked you to run, or the version that did not work first. Put a line of your own code on screen for three seconds. Almost nobody does, and it is the most convincing three seconds in the video.
Show your work has the template. Tag it #BozomaBuilds.