blocks / nano-led-fade
LED fade on a Nano
An LED on D9 of an Arduino Nano fades up and down by PWM.
on Nano (CH340 clone)4 parts1 test
orbe add nano-led-fade
Loading the Block
An LED on D9 of an Arduino Nano fades up and down by PWM.
firmware/fade/fade.ino 277 BRaw
int led = 9;
int brightness = 0;
int fadeAmount = 5;
void setup() {
pinMode(led, OUTPUT);
}
void loop() {
analogWrite(led, brightness);
brightness = brightness + fadeAmount;
if (brightness <= 0 || brightness >= 255) {
fadeAmount = -fadeAmount;
}
delay(30);
}
scene.jsonc 880 BRaw
// An LED on D9 of a Nano fades up and down by PWM, built on a half-size breadboard.
// The Nano straddles the center channel over columns 1 to 15. D9 is column 4 on the f to j side.
{
"format": 1,
"parts": {
"bb": { "type": "breadboard-400" },
"nano": { "type": "nano-board", "firmware": "build/fade.ino.hex" },
"r1": { "type": "resistor-axial", "resistance": "220" },
"led1": { "type": "led-5mm" },
},
"layout": {
"bb": { "at": [0, 0, 0] },
"nano": { "on": { "D13": "bb.d1" } },
"r1": { "on": { "a": "bb.i20" } }, // b in column 24
"led1": { "on": { "anode": "bb.h24" } }, // cathode in column 25
},
"nets": { "GND": "nano.GND" },
"wires": [
["bb.j4", "bb.j20"], // D9 to r1.a
["bb.j12", "bb.Z13", { "color": "#161616" }], // GND to the - rail
["bb.j25", "bb.Z25", { "color": "#161616" }], // led1.cathode to GND
],
}
tests/fade.test 565 BRaw
# The sketch adds 5 to the PWM duty every 30 ms, up to 255 and back down. brightness is the # average forward current over 20 ms, so the rise and the fall can be checked. One sample of # D9 cannot, because analogWrite on D9 is about 490 Hz. open step 10ms expect @led1 off expect @led1.brightness < 100uA step 590ms expect @led1 lit expect @led1.brightness > 3mA expect @led1.brightness < 7mA step 940ms expect @led1 lit expect @led1.brightness > 10mA step 1470ms expect @led1 dim expect @led1.brightness > 100uA expect @led1.brightness < 2mA expect no diagnostics
orbe add writes these files.
How it works
The sketch steps analogWrite on D9 from 0 to 255 and back by 5 every 30 ms, so the LED fades up and down about every 3 seconds. 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)fade.ino.hex
- 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 | 271 B |
| block.jsonc | 403 B |
| build/fade.ino.hex | 3.3 kB |
| firmware/LICENSE-libc | 2.5 kB |
| firmware/LICENSE-runtime | 26.4 kB |
| firmware/NOTICE | 1.5 kB |
| firmware/fade/fade.ino | 277 B |
| scene.jsonc | 880 B |
| tests/fade.test | 565 B |