Yifan Chen - skill dev 3

Made by yifanch2

Created: November 18th, 2021

0

Exercise 1 Modify the code to light up pixel by pixel then reverse the sequence turning each pixel off one by one

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

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

}
Click to Expand
0

Exercise 2  Modify the code to light up blue, then red, then green then white in sequence

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

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

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

    uint32_t g = strip.Color(0, 255, 0);

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

    uint32_t w = strip.Color(255, 255, 255);

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


}
Click to Expand
0

Exercise 3  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 i.e. build a single pixel that will continually cycle

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

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



}
Click to Expand
0

Exercise 4 

 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
int setRed(string str){
    
    int pix = str.toInt();
    
    uint32_t redC = strip.Color(pix,0,0);
    
    for(unit16_t i = 0; i<strip.numPixels();i++){
        strip.setPixelColor(i, redC);
        strip.show();
        delay(200);
    }
    
    return -1;
}

int setGreen(string str){
    
    int pix = str.toInt();
    
    uint32_t greenC = strip.Color(0,pix,0);
    
    for(unit16_t i = 0; i<strip.numPixels();i++){
        strip.setPixelColor(i, greenC);
        strip.show();
        delay(200);
    }
    
    return -1;
}


int setBlue(string str){
    
    int pix = str.toInt();
    
    uint32_t BlueC = strip.Color(0,0,pix);
    
    for(unit16_t i = 0; i<strip.numPixels();i++){
        strip.setPixelColor(i, BlueC);
        strip.show();
        delay(200);
    }
    
    return -1;
}
Click to Expand
0

Ambient Calendar Alert

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

// 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);

uint8_t i = 0;

unsigned long lastFade = 0;

void setup() {
    
    strip.begin();
    uint32_t c = strip.Color(0, 0, 0); // white
    for( uint16_t a = 0; a < strip.numPixels(); a++ ){
        strip.setPixelColor(a, c); // set white
    }
    
    
}



void loop() {
    
    
    unsigned long now = millis();
    
    if((now-lastFade)<=15 * 60 * 1000)
    {
        i+1;
        uint32_t c = strip.Color(i, 0, 0);
        
        for( uint16_t x = 0; x < strip.numPixels(); x++ ){
        strip.setPixelColor(x, c);
        }
        
        delay(3600);
    }
    
    else if((now-lastFade)>15 * 60 * 1000){
        i-1;
        uint32_t c = strip.Color(i, 0, 0);
        for( uint16_t x = 0; x < strip.numPixels(); x++ ){
        strip.setPixelColor(x, c);
        }
        
        delay(3600);
    }
    
    

}
Click to Expand
1

My neopixel is not working. Will update the picture after I fix it. 

x