Skills Dev III: Ambient Orb-Hongyu Mao
Made by Hongyu Mao
Made by Hongyu Mao
In this exercise, I followed up with the tutorial and finally made a device connect to Google Calendar and it will give me an ambient notification for a new update of the event.
Created: December 15th, 2021
// This #include statement was automatically added by the Particle IDE.
#include <neopixel.h>
#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()
{
for(int i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, 255, 0, 0 );
strip.show();
delay(1000);
}
delay(1000) ;
for(int i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, 0, 0, 0 );
strip.show();
delay(1000);
}
}
Click to Expand
nclude <neopixel.h>
#include "neopixel.h"
#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;
for(i=0; i< strip.numPixels(); i++) {
strip.setPixelColor(i, 0,255,255 );
strip.show();
delay( 200 );
strip.setPixelColor(i, 0, 0, 0 );
}
}
Click to Expand
// This #include statement was automatically added by the Particle IDE.
#include <neopixel.h>
#include "neopixel.h"
#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("R", setRed);
Particle.function("G", setGreen);
Particle.function("B", setBlue);
}
void loop() {
uint16_t i;
for(i=0; i< strip.numPixels(); i++) {
strip.setPixelColor(i, red, green, blue);//blue
//strip.setPixelColor(i, 0, 0, 0 );
}
strip.show();
// delay( 1000 );
}
int setRed(String command){
int number = atoi(command);
if(number >=0 && number <= 255){
red = number;
}
return red;
}
int setGreen(String command){
int number = atoi(command);
if(number >=0 && number <= 255){
green = number;
}
return green;
}
int setBlue(String command){
int number = atoi(command);
if(number >=0 && number <= 255){
blue = number;
}
return blue;
}
Click to Expand
// This #include statement was automatically added by the Particle IDE.
#include <neopixel.h>
#include "neopixel.h"
#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;
unsigned long lastFade = 0;
int redPercentage=255;
// bool goingRed = true;
int goingRed = 1;
void setup() {
strip.begin();
strip.show();
Particle.function("Red", setRed);
}
void loop() {
unsigned long now = millis();
if(red == 1){
if ((now - lastFade) >= 500) {
if (goingRed == 1) {
redPercentage = redPercentage - 2.5;
// Particle.publish("It is going red now");
if(redPercentage <= 0){
redPercentage = 0;
goingRed = 0;
}
}
else if(goingRed == 0) {
redPercentage = redPercentage + 2.5;
// Particle.publish("It is going white now");
if(redPercentage >= 255){
redPercentage = 255;
goingRed = 1;
red = 0;
}
}
lastFade=now;
}
}
for(uint16_t i=0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, 255, redPercentage, redPercentage);
}
strip.show();
}
int setRed(String command){
int number = atoi(command);
if(number == 1){
red = 1;
}
return red;
}
Click to Expand