Skills Dev III _xuyangj

Made by Xuyang Jin · UNLISTED (SHOWN IN POOLS)

To create an ambient calendar alert using a neopixel strip.

Created: November 24th, 2020

0

Intention

This week, we have learnt how to deal with neopixel and I would like to connect the device to Google Calendar through IFTTT eventually. I start from some small practice to light up the neopixel in different ways. 

0

Approach

exercise 1: 

Light up pixel by pixel then reverse the sequence turning each pixel off one by one.

0
#include <neopixel.h>


// IMPORTANT: Set pixel COUNT, PIN and TYPE
#define PIXEL_PIN D3
#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(255, 255, 255);

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

	delay( 100 );

}
Click to Expand
0
0

exercise 2:

  light up blue, then red, then green then white in sequence . 

0
#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);

void setup() {

  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
}

void loop() {

  uint16_t i;
  uint32_t c1 = strip.Color(0, 0, 255);
  uint32_t c2 = strip.Color(255, 0, 0);
  uint32_t c3 = strip.Color(0, 255, 0);
  uint32_t c4 = strip.Color(255, 255, 255);

  for(i=0; i< strip.numPixels(); i++) {
    strip.setPixelColor(i, c1 );
		strip.show();
		delay( 100 );
  }
  for(i=0; i< strip.numPixels(); i++) {
    strip.setPixelColor(i, c2 );
		strip.show();
		delay( 100 );
  }
  for(i=0; i< strip.numPixels(); i++) {
    strip.setPixelColor(i, c3 );
		strip.show();
		delay( 100 );
  }
  for(i=0; i< strip.numPixels(); i++) {
    strip.setPixelColor(i, c4 );
		strip.show();
		delay( 100 );
  }
  
	
	delay( 100 );

}
Click to Expand
0
0

Exercise3: 

Change the code to only 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  

0
#include <neopixel.h>


// IMPORTANT: Set pixel COUNT, PIN and TYPE
#define PIXEL_PIN D3
#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(255, 255, 255);

 for(i=0; i >= 0 ; i++) {
    if (i == 15){
        strip.setPixelColor(0, c );
        strip.setPixelColor(i, 0 );
        i = i - 16;
	    strip.show();
	    delay( 100 );
  }else{
        strip.setPixelColor(i+1, c );
        strip.setPixelColor(i, 0 );
	    strip.show();
	    delay( 100 );
  }}
  
	

}
Click to Expand
0
0

Then finally, I connected the Particle device to Google Calendar through IFTTT and it will send me a pixel lighting signal to alert 15 minutes before an appointment. 

15 minutes before an appointment, the neopixel will turn red and when the meeting starts it switch to white. 

0
#include <neopixel.h>


// IMPORTANT: Set pixel COUNT, PIN and TYPE
#define PIXEL_PIN D3
#define PIXEL_COUNT 16
#define PIXEL_TYPE WS2812

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

long timeAtParticleFuction = 0;
long turnOffAfter = 15*60*1000;

bool lightStatus = false;

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

  
}

int turnOn(String command)
{
   lightStatus = true;
   timeAtParticleFuction = millis();
   return 0;
   
}
int turnOff(String command)
{
   lightStatus = false;
   timeAtParticleFuction = millis();
   return 0;
   
}

void loop() {


 uint16_t i;
 uint32_t cred = strip.Color(255, 0, 0);
 uint32_t cwhite = strip.Color(255, 255, 255);

 if(lightStatus == true){
      for(i=0; i< strip.numPixels(); i++) {
        strip.setPixelColor(i, cred );
      }
		strip.show();
		
  }else{
      for(i=0; i< strip.numPixels(); i++) {
        strip.setPixelColor(i, cwhite );
      }
		strip.show();

}

}
Click to Expand
0
0

All the exercises above are using the same simple circuit as the below image shows.

0

Process

The process went on smoothly and everything works as required. Although the final project has a slight delay on neopixel due to the internet delays, the project is a great indicator for future appointments. It is good to know how to connect other applications through IFTTT to my circuit. 

0

Reflection

This project is really interesting. It is good to know how to connect other applications through IFTTT to my circuit. This is the first time that I felt like even the simple connected circuit could help our life and the design doesn't have to be too complex to put into practice. And this really inspired me to further design on IoT to make more simple circuits for practical use. 

IFTTT is really useful because it provide quite a lot opportunities to make connections. I would like to try more on it.

x
Share this Project

This project is only listed in this pool. Be considerate and think twice before sharing.


Courses

About

To create an ambient calendar alert using a neopixel strip.