Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Christmas 2014 LED dot matrix on balcony.
- This sketch controls 50 RGB LEDs controlled by WS28x1
- and displays digit 1-31.
- May 2014 - rediculum
- */
- // Libs
- #include <avr/pgmspace.h>
- #include "FastLED.h"
- #include <Wire.h>
- #include <RealTimeClockDS1307.h>
- #include "BitBool.h"
- #include "XMas14_RGB.h"
- // Pin outs
- /*
- RTC SDA = A4
- RTC SCL = A5 */
- #define DATA_PIN 3
- //#define CLOCK_PIN 13
- // Define the array of leds and var declarations
- #define NUM_LEDS 50 // Change also in BitBool
- #define DURATION 30000 // Duration of an animation (except fading)
- byte today, arrSize, arrElement, indicator;
- unsigned long endtime;
- CRGB leds[NUM_LEDS];
- void setup() {
- Serial.begin(9600);
- Serial.println(F("XMas14 RGB Lights"));
- //FastLED.addLeds<WS2801, RGB>(leds, NUM_LEDS);
- FastLED.addLeds<WS2811, DATA_PIN, RGB>(leds, NUM_LEDS);
- Serial.print(F("Test run"));
- for (byte i = 0; i < 50; i++) {
- leds[i]= CHSV(64,64,64);
- FastLED.show();
- delay(50);
- }
- delay(3000);
- for (byte i = 0; i < 50; i++) {
- leds[i]= CHSV(0,0,0);
- FastLED.show();
- delay(50);
- }
- indicator = 0;
- }
- void loop() {
- // Read day from RTC
- RTC.readClock();
- today = RTC.getDay();
- //today = 24;
- //for (today = 10; today < 32; today++) {
- // Count amount of bits (1) in matrix for that row (today) and define the array size
- arrSize = 0;
- for (byte i = 0; i < 50; i++) {
- leds[i].maximizeBrightness();
- if (matrix[today][i] == 1) {
- arrSize++;
- }
- }
- byte numArray[arrSize];
- Serial.print(F("Displaying number: "));
- Serial.print(today);
- Serial.print(F(" (array size "));
- Serial.print(arrSize);
- Serial.println(F(")"));
- // Fill the LED number into the defined array.
- // Array element 0 is LED 1, element 49 is LED 50, and so on!
- Serial.print(F("LEDS: "));
- arrElement = 0;
- for (byte i = 0; i < NUM_LEDS; i++) {
- if (matrix[today][i] == 1) {
- numArray[arrElement] = i;
- Serial.print(numArray[arrElement]); Serial.print(F(" "));
- arrElement++;
- }
- }
- Serial.println(F(""));Serial.println(F("---------------------")); // Separator
- delay(100);FastLED.clear();delay(100);
- // Light up randomly one LED light blue (Aqua)
- Serial.print(F("Light up dots ... "));
- endtime = millis() + DURATION;
- while (millis() < endtime) {
- byte led = random(0,NUM_LEDS - 1);
- fadeOutColour(led,0,128);
- delay(random(1,500));
- }
- Serial.println(F(" done"));
- delay(100);FastLED.clear();delay(100);
- Serial.print(F("Fade in ... "));
- // Fade in new number with random colours
- for (byte i = 0; i < arrSize; i++) {
- //Serial.print(numArray[i]); Serial.print(F(" "));
- fadeInColour(numArray[i],random(0,255));
- delay(3);
- }
- Serial.println(F(" done"));
- delay(DURATION);
- // Randomly change color of a single LED
- Serial.print(F("Random Color change ... "));
- endtime = millis() + DURATION;
- while (millis() < endtime) {
- setColour(numArray[random(0,arrSize)],random8());
- FastLED.show();
- delay(100);
- }
- Serial.println(F(" done"));
- // Rainbow single LEDs
- Serial.print(F("Rainbow single .."));
- byte divider = 255 / arrSize;
- endtime = millis() + DURATION;
- while (millis() < endtime) {
- for (byte led = 0; led < arrSize; led++) {
- leds[numArray[led]] = CHSV((indicator * divider),255,255);
- indicator++;
- }
- FastLED.show();
- delay(100);
- }
- Serial.println(F(" done"));
- // Rainbow with all LEDs at once
- Serial.print(F("Rainbow all ..."));
- endtime = millis() + DURATION;
- while (millis() < endtime) {
- for (byte color = 0; color < 255; color++) {
- for (byte led = 0; led < arrSize; led++) {
- setColour(numArray[led],color);
- }
- FastLED.show();
- delay(100);
- }
- }
- Serial.println(F(" done"));
- Serial.print(F("Fade out ... "));
- // Fade out bright
- for (byte i = 0; i < arrSize; i++) {
- //Serial.print(numArray[i]); Serial.print(F(" "));
- fadeOutColour(numArray[i],128,255);
- delay(3);
- }
- Serial.println(F(" done"));
- Serial.println(F(""));Serial.println(F("End of loop"));Serial.println(F(""));
- if (millis() > 4294000000) {
- asm volatile (" jmp 0"); // Soft Reset after 49 days
- }
- //}
- }
- //================================================================================================
- // Fades in one LED in by a given colour 0-255)
- void fadeInColour(byte led, byte hue){
- for (byte i = 0; i < 255; i++) {
- leds[led] = CHSV(hue,255,i);
- FastLED.show();
- delayMicroseconds(300);
- }
- }
- // Fades out one LED in by a given colour 0-255)
- void fadeOutColour(byte led, byte sat, byte hue){
- for (byte i = 255; i > 0; i--) {
- leds[led] = CHSV(hue,sat,i);
- FastLED.show();
- delayMicroseconds(300);
- }
- }
- // Sets one LED to a specified colour.
- // Does not invoke FastLED.show()!
- void setColour(byte led, byte hue) {
- leds[led] = CHSV(hue,255,255);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement