Crack the Code · Stage 4
Use digital and analog inputs to control outputs. Read a button with `digitalRead`, a potentiometer/LDR with `analogRead`, and drive an LED and a piezo buzzer. Use the Serial Monitor to inspect what your program is doing.
Open this deck on the projector and press F for full-screen. N toggles speaker notes. The accompanying teacher guide is at /curriculum/crack-the-code/teacher/lessons/3.
Before this lesson:
_02_Button, _03_int, _05_analog_input, _07_Buzzer1.Use digital and analog inputs to control outputs. Read a button with digitalRead, a potentiometer/LDR with analogRead, and drive an LED and a piezo buzzer. Use the Serial Monitor to inspect what your program is doing.
_02_Button, _03_int, _05_analog_input, _07_Buzzer1.1023 − sensorValue; LEDs scroll as you turn the dial; a night light that
turns the LED on when the LDR reading is low); evaluation questions.int command in context (intuitive pin names; easy pin changes).tone command). Optionally screen the VEA Introduction to
Programming video.if/else).int command to give a pin a friendly name in code.= vs == — single = assigns; double == compares. The compiler won't always catch this.analogRead returns 0–1023, not 0–255. The delay(sensorValue) trick visualises this.Which of the three PRPs felt closest to your alarm idea? What input + output will your alarm use?
End of lesson 3
Tomorrow / next lesson: Generating, developing & testing design ideas.