Often I'd forget what time it is while working at my desk. Often while texting a friend I'll be reminded it's past midnight with how discord records a new day just to really show how bad my sleep schedule is.
Well, I figured instead of having discord calling me out and my friends and I nagging at each other to go to bed why not have my lights do that? hopefully, at least my sleep schedule will improve now.
Starting outI'm not sure how other desk setups are but since in my house space is very limited when I finally got a desk it was under a lofted bed in a corner with a drawer blocking the view to the window, in short; it's really small and really dark here for a while I was just in complete darkness until eventually I went to target and got these really cheap fairy lights I figured I could string up between the support boards in the bed above me. It was actually really pretty at first then they started to dull very quickly for some reason "well that's a shame but I suppose they were cheap after all" I had said but I got the idea to just plug the USB into the outlet itself instead of the battery pack it came with and discovered the brightness was just entirely voltage.
The initial plan was just to connect my lights through a USB adapter to my argon however I made the mistake of forgetting that the argon doesn't give off 5V it gives 3.3V. It was a bit annoying but parts were already ordered when I discovered my mistake and since the goal was just a signal and my area was already pitch black the brightness from 3.3V was fine enough.
Because I didn't wire anything extra to draw more power it was a simple wiring design, I soldered together the USB adapter and hooked it up with ease. Note: I had actually tested with the potentiometer just to double-check the lights could be controlled by analog.
Coding was- something, I'm not the best at coding so thankfully particle has a built-in time function. It was just simply getting the time zone, figuring out what time I should have the "you should sleep soon" signal sent, and then what exactly that signal was. I was playing around with it for a bit because I didn't want it to just blink on and off because I'd rather not strobe myself late at night. I figured out how to make them fade just by creating an equation to raise and lower the voltage. with that done just needed to put it together, now the speed is still kind of strobing but it's easier on the eyes than just on/off it's also easily configurable so if I am annoyed with it as time goes on I'll edit it.
int Pl = 0; //Birghtness
int Ff = 5; //fade factor
// fade
Pl = Pl + Ff;
// reverse
if (Pl <= 0 || Pl >= 255) {
Ff = -Ff;
delay(100); //so while Ff controls the value of the output brightness each time this also controls the speed at which the whole loop goes
}The lights flicker for a minute before going back to normal, about an hour later they will shut off entirely
At first, I did have it set where the lights would turn on again at around 9 but that wasn't the best option as I might not want to use my lights again at 9 or what if I needed them before or what if I was working really late at night and had needed to ignore the signal and now its 1 am and I'm tired and in the dark. I had added a simple button and changed the code a little.
really all that changed was adding the initial button code then making It a status boolean that would switch true/false every time the button was pressed, the loops would then have an added condition where the status would need to be true in order for the fade to work.
Now the whole point of this project was to 1. Learn 2. keep track of the world outside of my desk. When I pitched the idea I was told it was too easy so I just quickly said: "oh what if I add a weather API so the lights will mimic things like a thunderstorm" got approved and had to start researching. Particle has this tutorial on OpenWeatherApi, I looked into it and it seemed interesting. I set up the webhook and the key only included data I needed in the command and then where I got stumped was interpreting the data. in theory, it would've been simple enough once I figured out how to use the data as a trigger I would've just needed to create a "thundering" light equation but I just couldn't figure it out. Of course, had I asked I would've probably gotten it but I thought I could get it myself.
int led = 2;
int Pl = 0; //Birghtness
int Ff = 15; //fade factor
int TDelay = 0;
bool Thunder;
int Weather = 0;
void setup() {
Time.zone(- 6);
pinMode(led, OUTPUT);
//Particle.publish("GetWeatherData",PRIVATE );
Particle.subscribe(System.deviceID() + "/GetWeatherData/", myHandler, MY_DEVICES);
}
void myHandler(const char *event, const char *data) {
// Handle the integration response
float Weather = atof(data);
Serial.println(Weather);
}
void loop() {
analogWrite(led, Pl);
//Delay to call function (5 min)
if(TDelay == 60000){
Particle.publish("GetWeatherData", data, PRIVATE);
TDelay == 0;
}
if (Time.hour() == 22 && Time.minute() == 34)
{
// fade
Pl = Pl + Ff;
// reverse
if (Pl <= 0 || Pl >= 255) {
Ff = -Ff;
delay(100);
}
else if(Weather == 804)
{
Pl = Pl + Ff;
// reverse
if (Pl <= 0 || Pl >= 255) {
Ff = -Ff;
delay(100);
}
}
}
//else if(Thunder){
// Pl = Pl + Ff;
// reverse
// if (Pl <= 0 || Pl >= 255) {
// Ff = -Ff;
// delay(100);
// }
//}
else
{
digitalWrite(led, HIGH);
}
TDelay++;
}Even though the second part didn't work I still learned a decent amount, primarily to ask for help when I need it but also got some practice with APIs, webhooks, and a bunch of other things I attempted while trying to get the data to work, a lot of new methods just used in the wrong equation.


_zhWsCcSEcl.jpg?auto=compress%2Cformat&w=48&h=48&fit=fill&bg=ffffff)





Comments