# Isha Hans - Ambient Orb

Create an ambient calendar alert using a neopixel strip

Created: November 17th, 2021

0

## Outcome

• This should provide at least one clear illustration of the final outcome (photo or video as appropriate).
0

## Exercise 1: Learning to connect the Neopixel such that each pixel lights up one by one in Blue

0
``````// This #include statement was automatically added by the Particle IDE.
#include <neopixel.h>

#define PIXEL_PIN D2
#define PIXEL_COUNT 16
#define PIXEL_TYPE WS2812

void setup() {
strip.begin();

}

void loop() {
strip.show();
uint16_t i;
uint32_t c = strip.Color(0, 0, 255); // Blue

for( int i = 0; i < strip.numPixels(); i++ ){
strip.setPixelColor(i, c); // set a color
strip.show();
delay( 200 );
}

}``````
Click to Expand
0
Designing for IoT 3.1: updates to each individual pixel of Neopixel
Isha Hans
0

Exercise 2: Turning Neopixel on pixel by pixel and then reversing the sequence turning each pixel off one by one.

0
``````// This #include statement was automatically added by the Particle IDE.
#include <neopixel.h>

#define PIXEL_PIN D2
#define PIXEL_COUNT 16
#define PIXEL_TYPE WS2812

int numPixels = strip.numPixels();

void setup() {
strip.begin();
strip.show();

}

void loop() {

uint16_t i;
uint32_t c1 = strip.Color(0, 0, 255); // Blue

for( int i = 0; i < strip.numPixels(); i++ ){
strip.setPixelColor(i, c1); // set a color
strip.show();
delay( 200 );
}

uint32_t c2 = strip.Color(0, 0, 0); //turning off by removing color
for( int i = numPixels; i >0; i-- ){
strip.setPixelColor(i, c2); // set a color
strip.show();
delay( 200 );
}

}``````
Click to Expand
0
Designing for IoT 3.2: Turning Neopixel ring on and off pixel by pixel
Isha Hans
0

Exercise 3: Turning Neopixel on pixel by pixel in Blue and then reversing the sequence turning each pixel off one by one. This repeated as a cycle of Blue followed by a cycle of Green followed by a cycle of Red.

0
``````// This #include statement was automatically added by the Particle IDE.
#include <neopixel.h>

#define PIXEL_PIN D2
#define PIXEL_COUNT 16
#define PIXEL_TYPE WS2812

int numPixels = strip.numPixels();

void setup() {
strip.begin();
strip.show();

}

void loop() {

uint16_t i;
uint32_t c1 = strip.Color(0, 0, 255); // Blue

for( int i = 0; i < strip.numPixels(); i++ ){
strip.setPixelColor(i, c1); // set a color
strip.show();
delay( 100 );
}

uint32_t c2 = strip.Color(0, 0, 0); //turning off by removing color
for( int i = numPixels; i >0; i-- ){
strip.setPixelColor(i, c2); // set a color
strip.show();
delay( 100 );
}

uint32_t c3 = strip.Color(0, 255, 0); // Blue

for( int i = 0; i < strip.numPixels(); i++ ){
strip.setPixelColor(i, c3); // set a color
strip.show();
delay( 100 );
}

for( int i = numPixels; i >0; i-- ){
strip.setPixelColor(i, c2); // set a color
strip.show();
delay( 100 );
}

uint32_t c4 = strip.Color(255, 0, 0); // Blue

for( int i = 0; i < strip.numPixels(); i++ ){
strip.setPixelColor(i, c4); // set a color
strip.show();
delay( 100 );
}

for( int i = numPixels; i >0; i-- ){
strip.setPixelColor(i, c2); // set a color
strip.show();
delay( 100 );
}

}``````
Click to Expand
0
Designing for IoT 3.3: Turning Neopixel ring on and off pixel by pixel in three colors
Isha Hans
0

Exercise 4: Light up only one pixel at a time. With each loop move that pixel one position higher. When it reaches the final pixel, restart the sequence at zero i.e. build a single pixel that will continually cycle.

0
``````// This #include statement was automatically added by the Particle IDE.
#include <neopixel.h>

#define PIXEL_PIN D2
#define PIXEL_COUNT 16
#define PIXEL_TYPE WS2812

int numPixels = strip.numPixels();

void setup() {
strip.begin();
strip.show();

}

void loop() {

uint16_t i;
uint32_t c1 = strip.Color(240, 230, 70); // Blue
uint32_t c2 = strip.Color(0, 0, 0); //turning off by removing color

for( int i = 0; i < strip.numPixels(); i++ ){
strip.setPixelColor(i, c1); // set a color
strip.show();
delay( 400 );

strip.setPixelColor(i, c2); // set a color
strip.show();
delay( 400 );

}

}``````
Click to Expand
0
Designing for IoT 3.4: Neopixel, blinking one pixel at a time
Isha Hans
0
Exercise 5: Add three Particle.function to set the Red, Green and Blue components. Allow these values to be set from 0-255 and as they are set to change all of the pixels on the LED strip to that color.
0
``````// This #include statement was automatically added by the Particle IDE.
#include <neopixel.h>
#define PIXEL_PIN D2
#define PIXEL_COUNT 16
#define PIXEL_TYPE WS2812

void setup() {
strip.begin();
strip.show();
Particle.function("tomato", setRed);
Particle.function("spinach", setGreen);
Particle.function("blueberry", setBlue);

}

void loop() {

}

int setRed(String f){ //functions for particle.function start with an int and take only string commands

int rValue = f.toInt();  //first:convert string to number
uint32_t red = strip.Color(rValue, 0, 0); //second: use the newly converted int to define color

uint16_t i;
for (i=0; i < strip.numPixels(); i++){
strip.setPixelColor(i, red);
strip.show();
}

delay(500);

return 1;
}

int setGreen(String f){ //functions for particle.function start with an int and take only string commands

int gValue = f.toInt();  //first:convert string to number
uint32_t green = strip.Color(0, gValue, 0); //second: use the newly converted int to define color

uint16_t i;
for (i=0; i < strip.numPixels(); i++){
strip.setPixelColor(i, green);
strip.show();
}

delay(500);

return 1;
}

int setBlue(String f){ //functions for particle.function start with an int and take only string commands

int bValue = f.toInt();  //first:convert string to number
uint32_t blue = strip.Color(0, 0, bValue); //second: use the newly converted int to define color

uint16_t i;
for (i=0; i < strip.numPixels(); i++){
strip.setPixelColor(i, blue);
strip.show();
}

delay(500);

return 1;
}``````
Click to Expand
0
Designing for IoT 3.5: changing Neopixel's color through cloud
Isha Hans
0

Exercise 6: Create an ambient calendar alert using a Neopixel strip to send an alert to my device a few minutes before an appointment.

I broke this apart into pieces as advised on the website and first learnt how to work with mills()in order to change color from red to blue. It took me multiple attempts and many hours to understand the syntax, I'm still not an expert but I think I understand the logic of syntax better thanks to this struggle.

0
``````// This #include statement was automatically added by the Particle IDE.
#include <neopixel.h>
#define PIXEL_PIN D2
#define PIXEL_COUNT 16
#define PIXEL_TYPE WS2812

unsigned long lastUpdateValue = 0;
int brightness = 255;
uint16_t i;
uint32_t w = strip.Color(255, 255, 255); // soft white

void setup() {
strip.begin();
strip.show();
Particle.function("tomato", setRed);
// Particle.function("spinach", setGreen);
// Particle.function("blueberry", setBlue);

}

void loop() {
strip.show();

if(w == 255) {
for( int i = 0; i < strip.numPixels(); i++ ){
strip.setPixelColor(i, w); // set a color
}
}else{

unsigned long timeNow = millis();
if((timeNow-lastUpdateValue) >=1000){
if(brightness > 0){
for( int i = 0; i < strip.numPixels(); i++ ){
strip.setPixelColor(i, brightness, 0, 255-brightness); //shifting color over a period of time
}
strip.show();
brightness = brightness-10;
lastUpdateValue = timeNow;
}
}
}
}``````
Click to Expand
0
Designing for IoT 3.6: Using millis for Neopixel
Isha Hans
0

0