blocks / uno-button-led
Button and LED on an Uno
A button on D2 lights a red LED on D13 of an Arduino Uno, and the board's own L LED with it.
on Uno R3 compatible board6 parts1 test
orbe add uno-button-led
Loading the Block
A button on D2 lights a red LED on D13 of an Arduino Uno, and the board's own L LED with it.
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.4 kBRaw
// A button on D2 lights an LED on D13 of an Uno, and the board's own L LED with it.
// The Uno sits beside a half-size breadboard, and jumpers run from its headers to the holes.
{
"format": 1,
"parts": {
"uno": { "type": "uno-board", "firmware": "build/button.ino.hex" },
"bb": { "type": "breadboard-400" },
"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": {
"uno": { "at": [-90, 0, 0] },
"bb": { "at": [0, 0, 0] },
"btn1": { "on": { "a": "bb.f16" }, "rotate": [0, 0, 90] }, // across the channel: a in column 16, b in 14
"r2": { "on": { "a": "bb.b16" }, "rotate": [0, 0, -90] }, // b in X16, the - rail
"r1": { "on": { "a": "bb.d22" } }, // b in column 26
"led1": { "on": { "anode": "bb.c26" } }, // cathode in column 27
},
"nets": { "GND": "uno.GND" },
"wires": [
["uno.5V", "bb.W3", { "color": "#d12b2b" }],
["uno.GND", "bb.X3", { "color": "#161616" }],
["bb.a14", "bb.W14", { "color": "#d12b2b" }], // btn1.b to 5V
["uno.D2", "bb.j16"], // D2 to btn1.a
["uno.D13", "bb.c22"], // D13 to r1.a
["bb.a27", "bb.X27", { "color": "#161616" }], // led1.cathode to GND
],
}
tests/button.test 334 BRaw
# Pressing the button lights the LED and the Uno's L LED, and releasing it turns both off. open step 100ms expect @led1 off expect @uno.led_l off press @btn1 step --until @led1 lit --timeout 50ms expect @uno.D13 high step 20ms expect @uno.led_l lit release @btn1 step 50ms expect @led1 off expect @uno.led_l 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
- unoUno R3 compatible boardbutton.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 | 447 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.4 kB |
| tests/button.test | 334 B |