Skills Dev III - Akshay Soma
Made by Akshay Soma · UNLISTED (SHOWN IN POOLS)
Made by Akshay Soma · UNLISTED (SHOWN IN POOLS)
Build an LED notification for upcoming calendar event
Created: December 4th, 2021
// This #include statement was automatically added by the Particle IDE.
#include <neopixel.h>
// IMPORTANT: Set pixel COUNT, PIN and TYPE
#define PIXEL_PIN D2
#define PIXEL_COUNT 16
#define PIXEL_TYPE WS2812
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
long startTime = 0;
long endTime = 0;
long preTime = 0;
int event(String trigger);
//for light color iteration
int x = 255;
void setup() {
Particle.function("event", event);
strip.begin();
strip.show();
}
void loop() {
if(millis() < startTime){
for(int i = 0; i<16; i++){
uint32_t c = strip.Color(255, x, x);
strip.setPixelColor(i, c);
}
strip.show();
x--;
delay(3529);
}
if(millis() > startTime && millis() < endTime){
for(int i = 0; i<16; i++){
uint32_t c = strip.Color(255, x, x);
strip.setPixelColor(i, c);
}
strip.show();
x++;
delay(3529);
}
if(endTime > 0 && millis() > endTime){
strip.clear();
strip.show();
preTime = 0;
startTime = 0;
endTime = 0;
}
}
int event(String trigger){
strip.Color(255,255,255);
strip.show();
preTime = millis();
startTime = preTime + 900000;
endTime = startTime + 900000;
return 1;
}
Click to Expand
Describe the process you underwent to reach the outcome (problems encountered, how you resolved them, as well as, experiments, hacks, tests, refinments, iterations, failures)
I started the process by working through the guides to get the Neopixel to light up and learning how to manipulate the code to create interesting results. Next I signed up for IFTTT and got it setup to call the function for my code 15 minutes before an event started.
Finally, I started the first design of this project. I coded everything to work using the delay() command. There was no use of the loop section in the code. While that worked well, we discussed in class how this made the code difficult to interrupt for testing, so I went back to improve the design. I used the millis() command within the loop section, global variables, and multiple if statements to create something that was easier to test.
Reflect on the process of making this project. What did you learn? What would you do differently?
In my first implementation of the project, I learned how to call a function using IFTTT and write the code to fade from white to red and back. This helped me learn more about how the code executes and where to place a delay to manipulate if colors change across the ring together or if each pixel moves independently.
Moving from there, I learned how to use millis() to create better functioning code. It also taught me how I can compartmentalize pieces of a task into various sections using functions and if statements. If I were to do this differently, I would consider changing each pixel independently to make the transition from one color to the next even smoother.