Created
October 23, 2016 06:15
-
-
Save ArduinoBasics/b2918835cef34ef3a918da7f3a260e0b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* ================================================================================================================================================== | |
Project: Arduino Disco Ball Cake | |
LED chipset: ws2812B (IC Station item ID: 5248): http://goo.gl/uDQjZW | |
Author: Scott C | |
Created: 2nd June 2016 | |
Arduino IDE: 1.6.4 | |
FastLED library version: 3.0.3 | |
Website: http://arduinobasics.blogspot.com/p/arduino-basics-projects-page.html | |
Description: Create a random LED sequence - Disco effect | |
FastLED library information at http://fastled.io/ | |
FastLED library download from: https://github.com/FastLED/FastLED/ | |
====================================================================================================================================================*/ | |
#include "FastLED.h" // Requires the FastLED library | |
#define NUM_LEDS 64 // This is the number of LEDs in total. 1 ring = 16 LEDS, 2 rings = 32 LEDs, 4 rings = 64 LEDs. Change this value according to the number of LEDs in use. | |
#define DATA_PIN 9 // Digital pin 9 (D9) on Arduino will be connected to "Din" on LED ring. This LED ring only requires a Data line (no clock required). | |
byte hue = 0; // This variable will control the hue of the LEDs | |
int rnd = 0; // A variable used to hold a random number | |
CRGB leds[NUM_LEDS]; // Create an Array of LEDs | |
void setup() { | |
FastLED.addLeds<NEOPIXEL,DATA_PIN>(leds, NUM_LEDS); //Initialise the LED ring(s) | |
} | |
void loop() { | |
hue=hue+5; //Change the Hue slightly with every loop (makes a progressive rainbow effect) | |
randomSeed(analogRead(A0)); //Using a floating Analog Pin to provide better randomisation | |
rnd = random8(NUM_LEDS); //Randomly choose one of the LEDs | |
leds[rnd].setHSV(hue,255,255); //Set the randomly chosen LED to illuminate when "FastLED.show();" is called | |
FastLED.show(); //Update the LEDs to display the modified LED sequence. | |
delay(50); //The time between LED flashes. This is pretty quick. i.e. 20 flashes per second. | |
for(int i=0; i<NUM_LEDS; i++){ | |
leds[i].fadeToBlackBy( 180 ); //Fade every LED by 180. Increase this number to make the LEDs fade faster | |
} | |
FastLED.show(); //Update the LEDs to display the modified LED sequence | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment