SunRiseLamp "wake up more naturally"

If I’m not mistaken it was for 5 amp the reason I chose 6 amps for the trace was because the barrel connector I asume will handle 1 amp more in small amount of time. For the part number I need to get back to you I have that on my home computer :smile:

@peekay123 this is the part If I’m wrong I still haven’t order it so just let me know :slight_smile:
http://www.digikey.com/scripts/DkSearch/dksus.dll?Detail&itemSeq=204844437&uq=636073300238923814

@Jean-Pierre, the link doesn’t work for me :confused:

Thats weird well here’s digikey part number CP-102BH-ND

@Jean-Pierre, looks like the connector is rated for 5 amps MAX (at 24VDC). Can you post your latest layout? I have some suggestions on how your are routing those large traces along with some other traces.

I actually have done quite a bit of learning based around this so much thanks to you @Jean-Pierre.

Here is some cleaned up code with a bit of Time() added into it:

Lines I added are 346-351 and 366-374

https://github.com/cloudzombie/SunRiseLamp/blob/master/SunRiseLamp.ino

If anybody has any tips to get the serial monitor to always print the correct time? Or point me in the right direction for that, I would be much obliged.

Then the next step would be to have the SunRise turn itself off once it’s run length has completed.

When you start the function, you can set a timer that'll trigger after a predetermined amount of time.
Alternatively, you could attach a PIR motion sensor, and only have it turn of after a fixed period of inactivity, to make sure you aren't suddenly left in the dark.

Does the function

// 300 sec = 5 min example: 60*5=300 if 30 min 60*30 = 1800
#define Sun_RISE_LENGTH_IN_SEC 1800

// 300 sec = 5 min example: 60*5=300 if 30 min 60*30 = 1800
#define Sun_SET_LENGTH_IN_SEC 1800

Not act as that timer?

I was thinking of a one shot timer like these, but there’s a variety of ways to achieve this: https://docs.particle.io/reference/firmware/photon/#class-member-callbacks

You mean a replacement for this?


  Serial.print("Time: ");

  Time.format(Time.now(), "Now it's %I:%M%p.");

  Serial.print(Time.hour(1400647897));
//  Serial.print(Time.now()); // 1400647897
  Serial.print(Time.timeStr()); // Wed May 21 01:08:47 2014

If you use Time.setFormat("Now it's %I:%M%p."); once in setup(), that'll be your default format for future Time.timeStr().
Or you just use

  Serial.println(Time.format("Now it's %I:%M%p."));
  // or even fancier
  Serial.printlnf("Time: %s - and some arbitraty number %d", (const char*)Time.format("%I:%M%p."), i);

I've not checked all your code, but once in a while (e.g. once a day) you should call Particle.syncTime() to compensate RTC drift.

Thats awesome! looks grate. You got serial com to work? I don’t know why but for me if I try to run Serial.begin(9600); the photon led start blinking red. I have no I idea why I thought it had something with the neopixel library.
I personally haven’t had time to work on this as much as I wanted too.

With my limited understanding, I am thinking it is something with,

SYSTEM_THREAD(ENABLED);

Something in the threading of functions being executed, once the SunRise starts, serial monitor no longer spits out Time, so its dependent on what is operating.

1 Like

Thanks

That might be because it's 'stuck' in that for loop? And doesn't finish the loop until after the whole sequence has been completed, thus blocking the serial prints.

1 Like

Hey this is awesome thanks for sharing!

Thanks man.

1 Like

I changed a few things around, serial output still stops as soon as the light is activated, any better way to do that ?

void setup()
{
  
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
  
  Serial.begin(9600);
  
  Particle.syncTime();

  Time.zone(-7);

  //Comment this out if you don't want your Sunrise immediately
    //sunRise();
  
  //Comment this out if you don't want the SunSet immediately 
     //sunSet();
}

unsigned long lastSync = millis();

void serialEvent()
{
    Serial.print("Time");
    
    Time.format(Time.now(), "Now it's %I:%M%p. "); 
    
    Serial.print(Time.hour(1400647897));
    
    //  Serial.print(Time.now()); // 1400647897
    Serial.print(Time.timeStr()); // Wed May 21 01:08:47 2014

    delay(5000);
    
}
    
    
    
void loop()
{
    

  if(Time.hour() == SUN_RISE_HOUR){
      //Make the led start the sequence
      sunRise();
      
      
  if (millis() - lastSync > ONE_DAY_MILLIS){  
        Particle.syncTime();
        lastSync = millis();
       
  if(Time.hour() == SUN_SET_HOUR){
       //Make the LED fade off
       sunSet();
       
            }
        }    
       
    }

}



void sunRise(){
    
    //loop through all the colors in the array
    for(int i=0; i<=299; i++ ){
    
    //This will make the sun rise 
     int time = (Sun_RISE_LENGTH_IN_SEC / 300)*1000;
     delay(time);
    
    String hexstring = HexArray[i];
    
   //convert the hex color into RGB values for the neopixel function 
   int number = (int)strtol(hexstring, NULL, 16);

     int r = number >> 16;
     int g = number >> 8 & 0xFF;
     int b = number & 0xFF;
     
   //Set all pixels to the same color and after the loop is done show it
   for(int p=0; p<strip.numPixels(); p++) {
       
      strip.setPixelColor(p,r,g,b);
      strip.setBrightness(PIXEL_BRIGHTNESS);
      
    }
    strip.show();
     
    }
     
}


void sunSet(){
    
    //loop through all the colors in the array
     for(int i=300; i>=0; i-- ){
    
    //This will make the sun rise 
     int time = (Sun_SET_LENGTH_IN_SEC / 900)*1000;
     delay(time);
    
    String hexstring = HexArray[i];
    
   //convert the hex color into RGB values for the neopixel function 
   int number = (int)strtol(hexstring, NULL, 16);

     int r = number >> 16;
     int g = number >> 8 & 0xFF;
     int b = number & 0xFF;
     
   //Set all pixels to the same color and after the loop is done show it
   for(int p=0; p<strip.numPixels(); p++) {
       
      strip.setPixelColor(p,r,g,b);
      strip.setBrightness(PIXEL_BRIGHTNESS);
      
    }
    strip.show();
     
    
     
    }
     
}

first get rid of that blocking for-loop you are using, which was pointed out several posts ago…

also noteworthy, this is true for a long time:

if(Time.hour() == SUN_RISE_HOUR){
      //Make the led start the sequence
      sunRise();

if you are testing by speeding up the sunrise/set, you may stay in those loops for an hour at least…

4 Likes

@Cloud Hey yeah I’m testing some awesome code that @BulldogLowell sen’t me will post soon to github it will fix that problem your getting :smile:

Sounds good.

I have a TSL2561 sitting here, a LUX sensor, would be cool to have that outside with another photon and when the sunrises trigger the lamp, dreams…dreams.

1 Like