blocks / nano-button-led
Button and LED on a Nano
A button on D2 lights a red LED on D13 of an Arduino Nano, and releasing it turns the LED off.
on Nano (CH340 clone)6 parts1 test
orbe add nano-button-led
Loading the Block
A button on D2 lights a red LED on D13 of an Arduino Nano, and releasing it turns the LED off.
firmware/button/button.ino 308 BRaw
const int buttonPin = 2;
const int ledPin = 13;
int buttonState = 0;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
}
void loop() {
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
digitalWrite(ledPin, HIGH);
} else {
digitalWrite(ledPin, LOW);
}
}
scene.jsonc 1.5 kBRaw
// A button on D2 lights an LED on D13 of a Nano, built on a half-size breadboard.
// The Nano straddles the center channel over columns 1 to 15, so each of its pins has a strip of
// free holes beside it: D13 is column 1 on the a to e side, D2 column 11 on the f to j side.
{
"format": 1,
"parts": {
"bb": { "type": "breadboard-400" },
"nano": { "type": "nano-board", "firmware": "build/button.ino.hex" },
"btn1": { "type": "tactile-switch-6mm" },
"r2": { "type": "resistor-axial", "resistance": "10k" }, // pull-down, so D2 reads low while open
"r1": { "type": "resistor-axial", "resistance": "220" },
"led1": { "type": "led-5mm" },
},
"layout": {
"bb": { "at": [0, 0, 0] },
"nano": { "on": { "D13": "bb.d1" } },
"btn1": { "on": { "a": "bb.f22" }, "rotate": [0, 0, 90] }, // across the channel: a in column 22, b in 20
"r2": { "on": { "a": "bb.b22" }, "rotate": [0, 0, -90] }, // b in X22, the - rail
"r1": { "on": { "a": "bb.d25" } }, // b in column 29
"led1": { "on": { "anode": "bb.c29" } }, // cathode in column 30
},
"nets": { "GND": "nano.GND" },
"wires": [
["bb.a12", "bb.W11", { "color": "#d12b2b" }], // 5V to the + rail
["bb.a14", "bb.X14", { "color": "#161616" }], // GND to the - rail
["bb.a20", "bb.W20", { "color": "#d12b2b" }], // btn1.b to 5V
["bb.j11", "bb.j22"], // D2 to btn1.a
["bb.c1", "bb.c25"], // D13 to r1.a
["bb.a30", "bb.X29", { "color": "#161616" }], // led1.cathode to GND
],
}
tests/button.test 242 BRaw
# Pressing the button lights the LED, and releasing it turns the LED off. open step 100ms expect @led1 off press @btn1 step --until @led1 lit --timeout 50ms expect @nano.D13 high release @btn1 step 50ms expect @led1 off expect no diagnostics
orbe add writes these files.
How it works
A 10k pull-down holds D2 low while the button is open, and a 220 ohm resistor sets the LED's current.
Check it with orbe check scene.jsonc and run its tests with orbe test.
Parts in this circuit
- nanoNano (CH340 clone)button.ino.hex
- r2Resistor, 1/4 W axial10 kΩ
- r1Resistor, 1/4 W axial220 Ω
- led15 mm LED, red
License and files(MIT OR Apache-2.0) AND LGPL-2.1-or-later
| File | Size |
|---|---|
| README.md | 206 B |
| block.jsonc | 453 B |
| build/button.ino.hex | 2.5 kB |
| firmware/LICENSE-libc | 2.5 kB |
| firmware/LICENSE-runtime | 26.4 kB |
| firmware/NOTICE | 1.6 kB |
| firmware/button/button.ino | 308 B |
| scene.jsonc | 1.5 kB |
| tests/button.test | 242 B |