Kenny Harsono - Ambient Orb
Made by kharsono
Made by kharsono
Build proficiency in Neo Pixel & IFTTT
Created: November 18th, 2021
Different exercises are done to show different capabilities:
//EXCERCISE 1: Turning on Neopixel
// 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);
for(i=0; i< strip.numPixels(); i++) {
strip.setPixelColor(i, c );
strip.show();
delay( 100 );
}
delay( 500 );
}
Click to Expand
// EXCERCISE 2: Turning on Neopixel different color
// 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,0);
for (int j=0; j<4; j++) {
switch (j){
case 0:
c = strip.Color(0,0,255);
break;
case 1:
c = strip.Color(255,0,0);
break;
case 2:
c = strip.Color(0,255,0);
break;
case 3:
c = strip.Color(255,255,255);
break;
}
for(i=0; i< strip.numPixels(); i++) {
strip.setPixelColor(i, c );
strip.show();
delay( 100 );
}
delay( 1000 );
}
}
Click to Expand
//EXCERCISE 3: Turning on & off Neopixel itteratively
// 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);
for(i=0; i< strip.numPixels(); i++) {
strip.setPixelColor(i, c );
strip.show();
delay( 100 );
}
delay( 500 );
c = strip.Color(0,0,0);
for(i=0; i< strip.numPixels(); i++) {
strip.setPixelColor(i, c );
strip.show();
delay( 100 );
}
}
Click to Expand
// EXCERCISE 4: Inputting RGB value for Neopixel
// 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 colorFunc(const char *args);
void setup() {
strip.begin();
strip.show(); // Initialize all pixels to 'off'
Particle.function("colorFunc", colorFunc);
}
void loop() {
}
int colorFunc(const char *args) {
int R, G, B;
sscanf(args, "%d,%d,%d", &R, &G, &B);
uint16_t i;
uint32_t c = strip.Color(R, G, B);
for(i=0; i< strip.numPixels(); i++) {
strip.setPixelColor(i, c );
strip.show();
delay( 100 );
}
delay( 1000 );
return 1;
}
Click to Expand
// Final Exercise: Using calendar meeting to turn Nop
// 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 meetingFunc(String args);
unsigned long initialized = 0;
unsigned long timing = 0;
unsigned long now = 0;
void setup() {
strip.begin();
strip.show(); // Initialize all pixels to 'off'
Particle.function("Calendar Reminder", meetingFunc);
}
void loop() {
now = millis();
uint32_t c = strip.Color(0, 0, 0); // All Red
while (initialized == 1 && (now - timing) <= 900000) {
int set = map((now - timing), 0, 900000, 0, 255);
c = strip.Color(set, 0, 0);
for( int i = 0; i < strip.numPixels(); i++ ){
strip.setPixelColor(i, c); // set a color
}
strip.show();
Serial.print(set);
Serial.print(" ");
Serial.print(now);
Serial.print(" ");
Serial.println(timing);
delay(1000);
now = millis();
if ((now - timing) == 300000) {
initialized = 0;
Serial.println("Exit the while");
}
}
c = strip.Color(0, 0, 0);
for( int i = 0; i < strip.numPixels(); i++ ){
strip.setPixelColor(i, c); // set a color
}
strip.show();
delay(100);
}
int meetingFunc(String args) {
initialized = 1;
timing = millis();
return 1;
}
Click to Expand
The takeaways through these experiments are valuable to be utilized for future use cases:
All in all, IFTTT is very handy in future use cases for IoT. It is the basis of connecting hardware devices to multiple cloud application connected to electronics (phone, laptop & etc.).