Skip to content

Instantly share code, notes, and snippets.

@codeandmake
Last active March 1, 2021 20:03
Show Gist options
  • Save codeandmake/88c9105d0fb59a61465be8171f647aef to your computer and use it in GitHub Desktop.
Save codeandmake/88c9105d0fb59a61465be8171f647aef to your computer and use it in GitHub Desktop.
Arduino Nano LED Candle.ino
/*
* Copyright 2020 Code and Make (codeandmake.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
/*
* Simple flickering candle effect using up to 6 LEDs.
*
* This code accompanies the following Thingiverse project: https://www.thingiverse.com/thing:4113149
*/
/**
* PWM Pins on Arduino Nano are 3, 5, 6, 9, 10 and 11
* See: https://www.arduino.cc/reference/en/language/functions/analog-io/analogwrite/
*/
int ledPins[] = { 3, 5, 6, 9, 10, 11 };
/**
* Set each pin as an output
*/
void setup() {
for (int i = 0; i < sizeof(ledPins) / sizeof(int); i++) {
pinMode(ledPins[i], OUTPUT);
}
}
/**
* Set random values for each pin
*/
void loop() {
for (int i = 0; i < sizeof(ledPins) / sizeof(int); i++) {
analogWrite(ledPins[i], random(10, 255));
delay(random(10, 20));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment