Ambient Orb - Neopixel Ring : Priya Jain

Made by Priya Jain

The objective of this project is to work with neopixels and create an ambient orb that lights up when there is a google calendar event.

Created: November 17th, 2021

0

The first step in this project was getting the neopixel connected. I was using a 16x WS2812 neopixel. After getting. a white light, I changed the light to purple which is what you will see below. 

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(); // Initialize all pixels to 'off'
    

}

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

  for(i=0; i< strip.numPixels(); i++) {
    strip.setPixelColor(i, c );
		strip.show();
		delay( 100 );
  }
	
	delay( 100 );

}
Click to Expand
0

For the first exercise, changed the neopixel behavior by making it light up pixel by pixel and then turning off pixel by pixel. It was pretty simple - just an addition of another for loop. 

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(); // Initialize all pixels to 'off'
    


}

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

  for(i=0; i< strip.numPixels(); i++) {
    strip.setPixelColor(i, c );
		strip.show();
		delay( 300 );
  }
  

  for(i=strip.numPixels(); i>0; i--){
      strip.setPixelColor(i,strip.Color(0,0,0));
      strip.show();
      delay(300);
  }
	
	delay( 100 );

}
Click to Expand
0

For exercise 2, I modified the behavior of the neopixel so that each pixel lights up and turns off one at a time. This required a simple change to the structure of the code. 

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(); // Initialize all pixels to 'off'
    


}

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

  for(i=0; i< strip.numPixels(); i++) {
    strip.setPixelColor(i, c );
		strip.show();
		delay( 300 );
		
		strip.setPixelColor(i,strip.Color(0,0,0));
		strip.show();
		delay(300);
  }
  

//   for(i=strip.numPixels(); i>0; i--){
//       strip.setPixelColor(i,strip.Color(0,0,0));
//       strip.show();
//       delay(300);
//   }
	
	delay( 100 );

}
Click to Expand
0

For the third exercise, I made the neopixel blink the colors blue, red, green, and white in that order on repeat. I think I inefficiently coded this with the number of for loops I made. I think this could have been done with a nested loop somehow. 

0
#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(); // Initialize all pixels to 'off'
    


}

void loop() {
   uint16_t i;
  uint32_t c = strip.Color(127, 0, 255);
  
  uint32_t b = strip.Color(0,0,255);
  uint32_t r = strip.Color(255, 0, 0);
  uint32_t g = strip.Color(0,255,0);
  uint32_t w = strip.Color(255,255,255);
  
  for(i=0; i<strip.numPixels(); i++){
      strip.setPixelColor(i,b);
  }
  
  strip.show();
  delay(1000);
  
  for(i=0; i<strip.numPixels(); i++){
      strip.setPixelColor(i,r);
  }
  
    strip.show();
  delay(1000);
 
    for(i=0; i<strip.numPixels(); i++){
      strip.setPixelColor(i,g);
  }
  
  strip.show();
  delay(1000);
  
    for(i=0; i<strip.numPixels(); i++){
      strip.setPixelColor(i,w);
  }
  
  strip.show();
  delay(1000);

delay( 1000 );

}
Click to Expand
0

Now, I tried to set up a particle function and call that function using IFTTT. The idea was that when a google calendar event is added, 15 minutes before the event the neopixel will turn red. the end goal is to create an ambient orb that will fade to red over 15 minutes. But let's do this in baby steps. 

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 fadeInRed(String meetingStarting);


void setup() {
    strip.begin();
    strip.show(); // Initialize all pixels to 'off'
    
    Particle.function("red", fadeInRed);
    


}

void loop() {
//   uint16_t i;
//   uint32_t c = strip.Color(127, 0, 255);
  
//   uint32_t b = strip.Color(0,0,255);
//   uint32_t r = strip.Color(255, 0, 0);
//   uint32_t g = strip.Color(0,255,0);
//   uint32_t w = strip.Color(255,255,255);
  

}

  int fadeInRed(String red) {
      uint16_t i;
      uint32_t r = strip.Color(255, 0, 0);
       for(i=0; i<strip.numPixels(); i++){
      strip.setPixelColor(i,r);
       }
  strip.show();
  return 1;
}
Click to Expand
0

I had trouble using millis(). I felt like it wasn't really working how it should be. So I decided to code the fading a different way. The measures right now makes the light change much faster than 15 minutes and so is not as ambient as it could be. However, it does start 15 min before the meeting and consistently get brighter. 

0
#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 fadeInRed(String red);

unsigned long startMillis;
unsigned long currentMillis;
    const unsigned long period = 10;
    int brightness = 0;       //initial brightness
    byte increment = 3;



void setup() {
    strip.begin();
    strip.show(); // Initialize all pixels to 'off'
    
    Particle.function("red", fadeInRed);
    // startMillis = millis();
    


}

void loop() {
//     currentMillis = millis();  //get the current time

//   if (currentMillis - startMillis >= period) {
//     brightness += increment;    //will wrap round from 255 to 0 because brightness is an unsigned data type
//     startMillis = currentMillis;  //IMPORTANT to save the start time of the current LED brightness


}

  int fadeInRed(String red) {

      uint16_t i;
      int brightness = brightness + 5;
      uint32_t r = strip.Color(brightness, 0, 0);
      
    for(int b = 0; b<255; b+=3){
        uint32_t r = strip.Color(b, 0, 0);
    
       for(i=0; i<strip.numPixels(); i++){
      strip.setPixelColor(i,r);
       }
  strip.show();
  delay(3000);
    }
    return 1;
}
Click to Expand
x
Share this Project

Courses

About

The objective of this project is to work with neopixels and create an ambient orb that lights up when there is a google calendar event.