Skill Dev3 - Yang Bai
Made by yangb ·
Made by yangb ·
This is skill dev3 of DIoT
Created: December 13th, 2020
exercise 1:
Light up pixel by pixel then reverse the sequence turning each pixel off one by one.
#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() {
// here is to light up the pixel one by one
uint16_t i;
uint32_t c = strip.Color(0, 0, 255); //blue
for(i=0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, c );
strip.show();
delay( 100 );
}
delay( 100 );
// here is to turn off the pixel one by one
for(i=strip.numPixels(); i > 0; i--) {
strip.setPixelColor(i, 0 );
strip.show();
delay( 100 );
}
delay( 100 );
}
Click to Expand
#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() {
// here is to light up the pixel one by one
uint16_t i;
uint32_t c = strip.Color(0, 0, 255); //blue
for(i=0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, c );
}
strip.show();
delay( 100 );
c = strip.Color(255, 0, 0); //red
for(i=0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, c );
}
strip.show();
delay( 100 );
c = strip.Color(0, 255, 0); //green
for(i=0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, c );
}
strip.show();
delay( 100 );
c = strip.Color(255, 255, 255); //white
for(i=0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, c );
}
strip.show();
delay( 100 );
}
delay( 100 );
}
Click to Expand
#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() {
// here is to light up the pixel one by one
uint16_t i;
uint32_t c = strip.Color(0, 0, 255); //blue
for(i=0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(100);
strip.setPixelColor(i, 0);
}
delay( 100 );
}
Click to Expand
#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);
int red = 0;
int green = 0;
int blue = 0;
void setup() {
strip.begin();
strip.show(); // Initialize all pixels to 'off'
Particle.function("red", setRed);
Particle.function("green", setGreen);
Particle.function("blue", setBlue);
}
void loop() {
uint16_t i;
uint32_t c = strip.Color(red, green, blue); //set the color
for(i=0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, c);
}
strip.show();
delay( 100 );
}
int setRed(String cmd) {
int redInput = cmd.toInt();
if(redInput >= 0 and redInput <= 255){
red = redInput;
}else{
return -1;
}
return 1;
}
int setGreen(String cmd) {
int greenInput = cmd.toInt();
if(greenInput >= 0 and greenInput <= 255){
green = greenInput;
}else{
return -1;
}
return 1;
}
int setBlue(String cmd) {
int blueInput = cmd.toInt();
if(blueInput >= 0 and blueInput <= 255){
blue = blueInput;
}else{
return -1;
}
return 1;
}
Click to Expand
This project is only accessible by signed in users. Be considerate and think twice before sharing.
This is skill dev3 of DIoT