Skills Dev 3: Nicole
Made by Nicole Chu
Made by Nicole Chu
Skills Dev 3: Ambient Orb
Created: December 13th, 2020
For this Skills Dev, we created an ambient calendar alert using a neopixel strip. To understand how to do this, I first went through the Neopixel tutorial on the Lab site.
// 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);
void setup() {
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}
void loop() {
uint16_t i;
uint32_t c = strip.Color(0, 0, 255); // Blue
for(i=0; i< strip.numPixels(); i++) {
strip.setPixelColor(i, c );
strip.setBrightness(20);
}
strip.show();
delay( 100 );
}
Click to Expand
// 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);
void setup() {
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}
void loop() {
uint16_t i;
uint32_t c = strip.Color(0, 0, 255); // Blue
uint32_t d = strip.Color(0, 0, 0); // Off
for( int i = 0; i < strip.numPixels(); i++ ){
strip.setPixelColor(i,c); // set a color
strip.setBrightness(20);
strip.show();
delay( 500 );
}
delay( 100 );
for( int i = strip.numPixels(); i > 0; i-- ){
strip.setPixelColor(i, d); // set a color
strip.setBrightness(20);
strip.show();
delay( 500 );
}
}
Click to Expand
// 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);
void setup() {
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}
void loop() {
uint16_t i;
uint32_t blue = strip.Color(0, 0, 255); //white
uint32_t white = strip.Color(255, 255, 255); //white
uint32_t red = strip.Color(255, 0, 0); //red
uint32_t green = strip.Color(0, 255, 0); //green
//int colors[] = {blue,white, red, green};
for( int i = 0; i < strip.numPixels(); i++ ){
strip.setPixelColor(i, blue); // set a color
strip.setBrightness(20);
}
strip.show();
delay(700);
for( int i = 0; i < strip.numPixels(); i++ ){
strip.setPixelColor(i, red); // set a color
strip.setBrightness(20);
}
strip.show();
delay(700);
for( int i = 0; i < strip.numPixels(); i++ ){
strip.setPixelColor(i, green); // set a color
strip.setBrightness(20);
}
strip.show();
delay(700);
for( int i = 0; i < strip.numPixels(); i++ ){
strip.setPixelColor(i, white); // set a color
strip.setBrightness(20);
}
strip.show();
delay(700);
}
Click to Expand
// 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);
int pixelNum = 0;
void setup() {
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}
void loop() {
uint16_t i;
uint32_t blue = strip.Color(0, 0, 255); //blue
uint32_t off = strip.Color(0, 0, 0); //off
for( int i = 0; i < strip.numPixels(); i++ ){
if (i != pixelNum) {
strip.setPixelColor(i, off);
}
else {
strip.setPixelColor(i, blue); // set a color
strip.setBrightness(20);
}
}
pixelNum++;
if (pixelNum >= strip.numPixels()) {
pixelNum = 0;
}
strip.show();
delay(100);
}
Click to Expand
// 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);
int pixelNum = 0;
int redValue = 255;
int greenValue = 255;
int blueValue = 255;
void setup() {
strip.begin();
strip.show(); // Initialize all pixels to 'off'
Particle.function("red", redVal);
Particle.function("green", greenVal);
Particle.function("blue", blueVal);
}
int redVal(String val){
redValue = val.toInt();
return redValue;
}
int greenVal(String val){
greenValue = val.toInt();
return greenValue;
}
int blueVal(String val){
blueValue = val.toInt();
return blueValue;
}
void loop() {
uint16_t i;
for( int i = 0; i < strip.numPixels(); i++ ){
strip.setPixelColor(i, redValue, greenValue, blueValue); // set a color
strip.setBrightness(20);
}
strip.show();
delay( 100 );
Particle.process();
}
Click to Expand
This exercise asks us to create an ambient calendar alert using a neopixel strip. It is connected to Google Calendar through IFTTT and is able to send an alert to a device 15 minutes before an appointment. The neopixels will respond by fading up slowly to signal there’s an event, and changing color as the event approaches. Ultimately it will then fade out after the event has begun. The process is outlined in steps below:
// 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);
void setup() {
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}
void loop() {
uint16_t i;
uint32_t 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
// 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);
bool meetingStatus = false;
void setup() {
strip.begin();
strip.show(); // Initialize all pixels to 'off'
Particle.function("meeting_soon", meetingSoon);
}
int meetingSoon(String arg){
if (arg == "yes"){
meetingStatus = true;
} else if (arg == "no") {
meetingStatus = false;
}
return 0;
}
void loop() {
uint32_t white = strip.Color(255, 255, 255); // White
uint32_t red = strip.Color(255, 0, 0); // red
if (meetingStatus == true) {
for( int i=0; i< strip.numPixels(); i++) {
strip.setPixelColor(i, red);
strip.setBrightness(20);
}
strip.show();
delay( 100 );
} else {
for( int i=0; i< strip.numPixels(); i++) {
strip.setPixelColor(i, white);
strip.setBrightness(20);
}
strip.show();
delay( 100 );
}
}
Click to Expand
// 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);
bool meetingStatus = false;
unsigned long timeAtStart = 0;
unsigned long timeToFade = (60*1000); //one minute
float redVal = 255.0;
float greenVal = 255.0;
float blueVal = 255.0;
void setup() {
strip.begin();
strip.show(); // Initialize all pixels to 'off'
Particle.function("meeting_soon", meetingSoon);
}
int meetingSoon(String arg){
timeAtStart = millis();
if (arg == "yes"){
meetingStatus = true;
} else if (arg == "no") {
meetingStatus = false;
}
return 0;
}
void loop() {
uint32_t white = strip.Color(255, 255, 255); // White
uint32_t red = strip.Color(255, 0, 0); // red
uint32_t currentColor;
if (meetingStatus == true) {
unsigned long now = millis();
while (now - timeAtStart <= timeToFade){
now = millis();
greenVal -= (255/60);
blueVal -= (255/60);
currentColor = strip.Color(255, greenVal, blueVal);
for( int i=0; i< strip.numPixels(); i++) {
strip.setPixelColor(i, currentColor);
strip.setBrightness(20);
}
strip.show();
delay(1000);
}
} else {
for( int i=0; i< strip.numPixels(); i++) {
strip.setPixelColor(i, white);
strip.setBrightness(20);
}
strip.show();
delay( 100 );
}
}
Click to Expand
// 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);
bool meetingStatus = false;
bool redOn = false;
unsigned long timeAtStart = 0;
unsigned long timeToFade = (60*1000); //one minute
float redVal = 255.0;
float greenVal = 255.0;
float blueVal = 255.0;
void setup() {
strip.begin();
strip.show(); // Initialize all pixels to 'off'
Particle.function("meeting_soon", meetingSoon);
}
int meetingSoon(String arg){
timeAtStart = millis();
if (arg == "yes"){
meetingStatus = true;
} else if (arg == "no") {
meetingStatus = false;
}
return 0;
}
void loop() {
uint32_t white = strip.Color(255, 255, 255); // White
uint32_t red = strip.Color(255, 0, 0); // red
uint32_t currentColor;
if (meetingStatus == true) {
unsigned long now = millis();
while (now - timeAtStart <= timeToFade){
now = millis();
greenVal -= (255/60);
blueVal -= (255/60);
currentColor = strip.Color(255, greenVal, blueVal);
for( int i=0; i< strip.numPixels(); i++) {
strip.setPixelColor(i, currentColor);
strip.setBrightness(20);
}
strip.show();
delay(1000);
}
redOn = true;
}else if (meetingStatus == false && redOn == true){
greenVal = 0.0;
blueVal = 0.0;
unsigned long now = millis();
while (now - timeAtStart <= timeToFade){
now = millis();
greenVal += (255/60);
blueVal += (255/60);
currentColor = strip.Color(255, greenVal, blueVal);
for( int i=0; i< strip.numPixels(); i++) {
strip.setPixelColor(i, currentColor);
strip.setBrightness(20);
}
strip.show();
delay(1000);
}
redOn = false;
} else {
for( int i=0; i< strip.numPixels(); i++) {
strip.setPixelColor(i, white);
strip.setBrightness(20);
}
strip.show();
delay( 100 );
redOn = false;
}
}
Click to Expand
// 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);
bool meetingStatus = false;
bool redOn = false;
unsigned long timeAtStart = 0;
unsigned long timeToFade = (60*15000); //15 minutes
float redVal = 255.0;
float greenVal = 255.0;
float blueVal = 255.0;
void setup() {
strip.begin();
strip.show(); // Initialize all pixels to 'off'
Particle.function("meeting_soon", meetingSoon);
}
int meetingSoon(String arg){
timeAtStart = millis();
if (arg == "yes"){
meetingStatus = true;
} else if (arg == "no") {
meetingStatus = false;
}
return 0;
}
void loop() {
uint32_t white = strip.Color(255, 255, 255); // White
uint32_t red = strip.Color(255, 0, 0); // red
uint32_t currentColor;
if (meetingStatus == true) {
unsigned long now = millis();
while (now - timeAtStart <= timeToFade){
now = millis();
greenVal -= (255/60);
blueVal -= (255/60);
currentColor = strip.Color(255, greenVal, blueVal);
for( int i=0; i< strip.numPixels(); i++) {
strip.setPixelColor(i, currentColor);
strip.setBrightness(20);
}
strip.show();
delay(15000);
}
redOn = true;
}else if (meetingStatus == false && redOn == true){
greenVal = 0.0;
blueVal = 0.0;
unsigned long now = millis();
while (now - timeAtStart <= timeToFade){
now = millis();
greenVal += (255/60);
blueVal += (255/60);
currentColor = strip.Color(255, greenVal, blueVal);
for( int i=0; i< strip.numPixels(); i++) {
strip.setPixelColor(i, currentColor);
strip.setBrightness(20);
}
strip.show();
delay(15000);
}
redOn = false;
} else {
for( int i=0; i< strip.numPixels(); i++) {
strip.setPixelColor(i, white);
strip.setBrightness(20);
}
strip.show();
delay( 100 );
redOn = false;
}
}
Click to Expand
I really enjoyed this Skills Dev, and it provided a nice opportunity to test out what I've learned so far about for loops, millis(), Neopixels, and the Particle Cloud functions and Console app. It was also extremely helpful to follow the Lab site's suggestion of breaking the practice exercise in small steps, rather than jumping straight into IFTTT. This is a method I will definitely implement with future projects.
Next, I will be moving onto Skills Dev 4!