Isha Hans - Ambient Orb

Made by ihans

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

Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);

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 - https://youtu.be/hFoRVeTkiEQ
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

Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
  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 - https://youtu.be/S2PjvOGlURQ
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

Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
  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 - https://youtu.be/gyHg8f52C6M
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

Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
  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 - https://youtu.be/gh3F50T1qbA
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

Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);


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 - https://youtu.be/UcDJI6g2ffU
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

Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);

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 - https://youtu.be/cihnNm_9-T8
0

Reflection

  • I struggled with the particle.function (in exercise 5) because I realized I hadn't understood the syntax really well. This consumed a lot of time for me and I sought a classmate's help and learnt the following:
  • Functions for particle.function start with an 'int' and take only strings (not variables). Hence, first you call out the string through an int, then convert the string to an integer and then use the newly converted int to define something, which in this case is color.
  • Function always has to have a return command, I learnt this the hard way by learning how to writ ethe following syntax:

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;

0


x
Share this Project

Courses

Focused on
About

Create an ambient calendar alert using a neopixel strip