Light and Interactivity

Week 10_24-hour lighting feature

My idea is to create early morning and late afternoon ambient light followed by daytime clock shadow. 

I don’t have the board which has the RTC function, so I use the Arduino UNO and the millis() function to make the 24-hour lighting feature.

And I bought the WS2811 LED strip which is powered by 12V. An interesting feature of the strip is that it has three LEDs in each group, they will response to the program together. I don’t know if I could program the three ones separately.

So in the beginning, my idea was to add a clock function into this light. But since there are three LEDs take the place in the 30 degrees on the clock (see the diagram below), I had to change my mind and made the clock change by each 10 minutes.

Color changing and LED strip structure.

 

Coding

I use this piece of code to make the LED strip fading from one color to the next at a certain time:

 
if (minutes == 0) {
 for(uint8_t b = 1; b <255; b++) {
     strip.setPixelColor(0, 0, 1 * b , 0);
     strip.setPixelColor(5, 0, 1 * b , 0);
     
     strip.setPixelColor(1, 1, 1 * b , 1);
     strip.setPixelColor(4, 1, 1 * b , 1);
     
     strip.setPixelColor(2, 1 * b, 255/b , 0);
     strip.setPixelColor(3, 1 * b, 255/b , 0);
     
     strip.show();
     delay(120);
  };

  for(uint8_t b=255; b>0; b--) {
     strip.setPixelColor(0, 255/b, 255 , 1);
     strip.setPixelColor(5, 255/b, 255 , 1);

     strip.setPixelColor(1, 255/b+100, 1 * b , 1);
     strip.setPixelColor(4, 255/b+100, 1 * b , 1);
     
     strip.setPixelColor(2,  255, 1 , 50/b);
     strip.setPixelColor(3,  255, 1 , 50/b);
     strip.show();
     delay(120);
  };
 }//end if

And this to make the LED to move according to the time in order to create the shadow of clock’s hands.

 
strip.setPixelColor(seconds, 255, 1, 50); 
strip.setPixelColor(minutes, 255, 1, 50); 


LED strip test

This video is actually 12 minutes long, I speed it up.

The screen on left top corner shows the running time(day:hour:minute:second) counting by Arduino.

Test the effect within 12 minutes.

I fixed the LED strip on the back of the lamp I made two weeks ago.


The Arduino code here:

 
#include <Adafruit_NeoPixel.h>

#define PIN 6
const int numPixels = 6;    // number of pixels

// set up strip:
Adafruit_NeoPixel strip = Adafruit_NeoPixel(numPixels, PIN, NEO_GRB + NEO_KHZ800);


long day = 86400000; // 86400000 milliseconds in a day
long hour = 3600000; // 3600000 milliseconds in an hour
long minute = 60000; // 60000 milliseconds in a minute
long second =  1000; // 1000 milliseconds in a second

int hours = 0;
int minutes = 0;
int seconds = 0;

void setup(){
  Serial.begin (57600); 
  
  strip.begin();    // initialize pixel strip
  strip.clear();    // turn all LEDs off
  strip.show();     // Initialize all pixels to 'off'
}

void loop(){
 long timeNow = millis();
 
 int days = timeNow / day ;                                //number of days
 int hours = (timeNow % day) / hour;                       //the remainder from days division (in milliseconds) divided by hours, this gives the full hours
 int minutes = ((timeNow % day) % hour) / minute ;         //and so on...
 int seconds = (((timeNow % day) % hour) % minute) / second;
 delay(1000);
 Serial.print(days,DEC); 
 printDigits(hours);  
 printDigits(minutes);
 printDigits(seconds);
 Serial.println();  
 

//sunrise
if (minutes == 0) {
 for(uint8_t b = 1; b<255; b++) { 
     strip.setPixelColor(0, 0, 1 * b , 0); 
     strip.setPixelColor(5, 0, 1 * b , 0); 
     strip.setPixelColor(1, 1, 1 * b , 1); 
     strip.setPixelColor(4, 1, 1 * b , 1); 
     strip.setPixelColor(2, 1 * b, 255/b , 0); 
     strip.setPixelColor(3, 1 * b, 255/b , 0); 
     strip.show(); delay(120); }; 
  
  for(uint8_t b=255; b >0; b--) {
     strip.setPixelColor(0, 255/b, 255 , 1);
     strip.setPixelColor(5, 255/b, 255 , 1);

     strip.setPixelColor(1, 255/b+100, 1 * b , 1);
     strip.setPixelColor(4, 255/b+100, 1 * b , 1);
     
     strip.setPixelColor(2,  255, 1 , 50/b);
     strip.setPixelColor(3,  255, 1 , 50/b);
     strip.show();
     delay(120);
  };
 }//end if

//set all to bright white
if (minutes == 1) {
 for(uint8_t b = 1; b <255; b++) { 
     strip.setPixelColor(0, 255, 255 , 1* b); 
     strip.setPixelColor(5, 255, 255 , 1* b); 
     strip.setPixelColor(1, 255, 1 * b , 1* b); 
     strip.setPixelColor(4, 255, 1 * b , 1* b); 
     strip.setPixelColor(2, 255, 1 * b , 1* b+50); 
     strip.setPixelColor(3, 255, 1 * b , 1* b+50); 
     strip.show(); delay(120); }; 

  for(uint8_t b=255; b > 0; b--) {
     strip.setPixelColor(0, 255, 255 , 255);
     strip.setPixelColor(5, 255, 255 , 255);
     
     strip.setPixelColor(1, 255, 255 , 255);
     strip.setPixelColor(4, 255, 255 , 255);
     
     strip.setPixelColor(2, 255, 255 , 255);
     strip.setPixelColor(3, 255, 255 , 255);
     
     strip.show();
     delay(120);
  };
  
 }//end if
 
//day 
 if (minutes>1 & minutes<5) {
 strip.setPixelColor(seconds/10, 255, 1, 50); //red, blue,green
 strip.setPixelColor(seconds/10-1, 255, 255, 255);
   if (seconds/10 == 0) {
     strip.setPixelColor(5, 255, 255, 255);
    }
 }//end if    
 strip.show();  


//begin to sunset

//set all to gold
if (minutes == 5) {
 for(uint8_t b = 1; b<255; b++) {
     strip.setPixelColor(0, 255, 255/b , 255/b+150);
     strip.setPixelColor(5, 255, 255/b , 255/b+150);
     
     strip.setPixelColor(1, 255, 255/b , 255/b+110);
     strip.setPixelColor(4, 255, 255/b , 255/b+110);
     
     strip.setPixelColor(2, 255, 255/b , 255/b+50);
     strip.setPixelColor(3, 255, 255/b , 255/b+50);
     
     strip.show();
     delay(250);
  };
 }
 //sunset
if (minutes == 6) {
 for(uint8_t b = 1; b<255; b++) { strip.setPixelColor(0, 255/b, 1*b , 150/b); strip.setPixelColor(5, 255/b, 1*b , 150/b); strip.setPixelColor(1, 255/b+110, 1*b , 110/b); strip.setPixelColor(4, 255/b+110, 1*b , 110/b); strip.setPixelColor(2, 255, 0 , 50/b); strip.setPixelColor(3, 255, 0 , 50/b); strip.show(); delay(120); }; //set all to darkblue for(uint8_t b=255; b > 0; b--) {
     strip.setPixelColor(0, 0, 255 , 0);
     strip.setPixelColor(5, 0, 255 , 0);

     strip.setPixelColor(1, 110-255/b, 255 , 1);
     strip.setPixelColor(4, 110-255/b, 255 , 1);
     
     strip.setPixelColor(2,  b, 255/b , 1);
     strip.setPixelColor(3,  b, 255/b , 1);
     strip.show();
     delay(120);
  };
 }//end if

   //night 
 if (minutes>6) {
 strip.setPixelColor(seconds/10, 255, 255, 255); //red, blue,green
 strip.setPixelColor(seconds/10-1, 0, 255/minutes, 0);
   if (seconds/10 == 0) {
     strip.setPixelColor(5, 0, 255/minutes, 0);
    }
 }
 
}

void printDigits(byte digits){
 // utility function for digital clock display: prints colon and leading 0
 Serial.print(":");
 if(digits <10)
   Serial.print('0');
 Serial.print(digits,DEC);   
}

 

Then turn it into 24hrs.

Because I started shooting the 24hrs time lapse at 3:00pm, so I set the sunset time at 7:00pm, which was 4hrs after the program starting. Then the sunrise began at 6:00am, which was 14hrs since the program begun to run.

 
#include <Adafruit_NeoPixel.h>

#define PIN 6
const int numPixels = 6;    // number of pixels

// set up strip:
Adafruit_NeoPixel strip = Adafruit_NeoPixel(numPixels, PIN, NEO_GRB + NEO_KHZ800);


long day = 86400000; // 86400000 milliseconds in a day
long hour = 3600000; // 3600000 milliseconds in an hour
long minute = 60000; // 60000 milliseconds in a minute
long second =  1000; // 1000 milliseconds in a second

int hours = 0;
int minutes = 0;
int seconds = 0;

void setup(){
  Serial.begin (57600); 
  
  strip.begin();    // initialize pixel strip
  strip.clear();    // turn all LEDs off
  strip.show();     // Initialize all pixels to 'off'
}

void loop(){
 long timeNow = millis();
 
 int days = timeNow / day ;                                //number of days
 int hours = (timeNow % day) / hour;                       //the remainder from days division (in milliseconds) divided by hours, this gives the full hours
 int minutes = ((timeNow % day) % hour) / minute ;         //and so on...
 int seconds = (((timeNow % day) % hour) % minute) / second;
 delay(1000);
 Serial.print(days,DEC); 
 printDigits(hours);  
 printDigits(minutes);
 printDigits(seconds);
 Serial.println();  


//afternoon starts at 3pm
 if (hours>=0 & hours<3) { 
    strip.setPixelColor(seconds/10, 255, 1, 50); //red, blue,green 
    strip.setPixelColor(seconds/10-1, 255, 255, 255); 

  if (seconds/10 == 0) { 
    strip.setPixelColor(5, 255, 255, 255); 
  } 
 } 
//begin to sunset 
//set all to gold 
  if (hours == 4 & minutes>0 & minutes<30) {
   for(uint8_t b = 1; b <255; b++) { 
    strip.setPixelColor(0, 255, 255/b , 255/b+150); 
    strip.setPixelColor(5, 255, 255/b , 255/b+150); 
    strip.setPixelColor(1, 255, 255/b , 255/b+110); 
    strip.setPixelColor(4, 255, 255/b , 255/b+110); 
    strip.setPixelColor(2, 255, 255/b , 255/b+50); 
    strip.setPixelColor(3, 255, 255/b , 255/b+50); strip.show(); delay(7500); 
   }; 
  } 
 //sunset 
  if (hours == 4 & minutes>29 & minutes<59) {
   for(uint8_t b = 1; b &lt;255; b++) { 
     strip.setPixelColor(0, 255/b, 1*b , 150/b); 
     strip.setPixelColor(5, 255/b, 1*b , 150/b); 
     strip.setPixelColor(1, 255/b+110, 1*b , 110/b); 
     strip.setPixelColor(4, 255/b+110, 1*b , 110/b); 
     strip.setPixelColor(2, 255, 0 , 50/b); 
     strip.setPixelColor(3, 255, 0 , 50/b); 
     strip.show(); delay(2500); 
  }; 
 //set all to darkblue 
  for(uint8_t b=255; b > 0; b--) {
     strip.setPixelColor(0, 0, 255 , 0);
     strip.setPixelColor(5, 0, 255 , 0);

     strip.setPixelColor(1, 110-255/b, 255 , 1);
     strip.setPixelColor(4, 110-255/b, 255 , 1);
     
     strip.setPixelColor(2,  b, 255/b , 1);
     strip.setPixelColor(3,  b, 255/b , 1);
     strip.show();
     delay(2500);
  };
 }//end if
 
  //night 
 if (hours > 4 & hours < 14) {//here is where I made the mistake when I took the 24hrs video.
//I wrote the condition as "hours==5" 
//so the clock hand is still in the video
 strip.setPixelColor(seconds/10, 255, 255, 255); //red, blue,green
 strip.setPixelColor(seconds/10-1, 0, 255/minutes, 0);
   if (seconds/10 == 0) {
     strip.setPixelColor(5, 0, 255/minutes, 0);
    }
 }

 
//sunrise
if (hours == 14 & minutes>0 & minutes<30) {
 for(uint8_t b = 1; b&lt;255; b++) { 
     strip.setPixelColor(0, 0, 1 * b , 0);    
     strip.setPixelColor(5, 0, 1 * b , 0); 
     strip.setPixelColor(1, 1, 1 * b , 1); 
     strip.setPixelColor(4, 1, 1 * b , 1); 
     strip.setPixelColor(2, 1 * b, 255/b , 0); 
     strip.setPixelColor(3, 1 * b, 255/b , 0); 
     strip.show(); delay(2500); }; 
  for(uint8_t b=255; b > 0; b--) {
     strip.setPixelColor(0, 255/b, 255 , 1);
     strip.setPixelColor(5, 255/b, 255 , 1);

     strip.setPixelColor(1, 255/b+100, 1 * b , 1);
     strip.setPixelColor(4, 255/b+100, 1 * b , 1);
     
     strip.setPixelColor(2,  255, 1 , 50/b);
     strip.setPixelColor(3,  255, 1 , 50/b);
     strip.show();
     delay(2500);
  };
 }//end if

//set all to bright white
if (hours == 14 & minutes>29 & minutes<59) {
 for(uint8_t b = 1; b < 255; b++) { 
     strip.setPixelColor(0, 255, 255 , 1* b); 
     strip.setPixelColor(5, 255, 255 , 1* b); 
     strip.setPixelColor(1, 255, 1 * b , 1* b); 
     strip.setPixelColor(4, 255, 1 * b , 1* b); 
     strip.setPixelColor(2, 255, 1 * b , 1* b+50); 
     strip.setPixelColor(3, 255, 1 * b , 1* b+50); 
     strip.show(); 
     delay(2500); 
  }; 
  for(uint8_t b=255; b > 0; b--) {
     strip.setPixelColor(0, 255, 255 , 255);
     strip.setPixelColor(5, 255, 255 , 255);
     
     strip.setPixelColor(1, 255, 255 , 255);
     strip.setPixelColor(4, 255, 255 , 255);
     
     strip.setPixelColor(2, 255, 255 , 255);
     strip.setPixelColor(3, 255, 255 , 255);
     
     strip.show();
     delay(2500);
  };
  
 }//end if
 
//day 
 if (hours > 14) {
 strip.setPixelColor(seconds/10, 255, 1, 50); //red, blue,green
 strip.setPixelColor(seconds/10-1, 255, 255, 255);
   if (seconds/10 == 0) {
     strip.setPixelColor(5, 255, 255, 255);
    }
 }//end if    
 strip.show();  
 
}

void printDigits(byte digits){
 // utility function for digital clock display: prints colon and leading 0
 Serial.print(":");
 if(digits < 10)
   Serial.print('0');
 Serial.print(digits,DEC);   
}

There is a mistake in the 24hrs video, which happens after the sunset effect. The mistake of my code I found later at line 90 of the codes above.

This is my way to take the 24hrs time lapse. But the color quality of Gopro is too bad…

 

Conclusion:
1. To make the sunrise and sunset effects better, the color need to be adjusted. It seems that the color of sunrise is too reddish.

2. I need to think of a better fabrication. The one right now is delicate. And I had broken it when I took the video documentation.

3.I should choose another kind of LED strip to create the minute by minute responsive clock.

Ideas for the future:
1. Use the RTC library to have the real time.

2.Get the web API of the sunrise and sunset time of the city.

 

Useful tutorials:

https://github.com/tigoe/timepieces

https://learn.adafruit.com/adafruit-neopixel-uberguide/arduino-library

http://forum.arduino.cc/index.php?topic=42211.0

Arduino – Controlling a WS2812 LED strand with NeoPixel or FastLED

Arduino – LEDStrip effects for NeoPixel and FastLED

 

Leave a Reply

Your email address will not be published. Required fields are marked *