Yifan Chen - skill dev 3
Made by yifanch2
Made by yifanch2
Created: November 18th, 2021
Exercise 1 Modify the code to light up pixel by pixel then reverse the sequence turning each pixel off one by one
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
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
// 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
~