Back to Parent

// setup and neopixel
#include "Particle.h"
#include <neopixel.h>
SYSTEM_MODE(AUTOMATIC);
SerialLogHandler logHandler(LOG_LEVEL_INFO);

#define PIXEL_PIN SPI
#define PIXEL_COUNT 12
#define PIXEL_TYPE WS2812

Adafruit_NeoPixel strip(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);


// potentiometers to control color
int potPinR = A1;
int potPinB = A2;
uint32_t c = 0;
bool shouldChangeColor = false;
String calEvent = "";

void setup() {
    Serial.begin(9600);
    Particle.function("calendarEvent",handleCalendarEvent);
}

void loop() {
    updateColor();
    
    strip.begin();
    for ( int i=0; i<strip.numPixels(); i++ ) {
        strip.setPixelColor(i,c); // set a color
    }
    strip.show();
    // delay(2000);
}

void updateColor() {
    if (shouldChangeColor) {
        if (calEvent == "focus") { c = strip.Color(144,241,168,255);
        } else if (calEvent == "meeting") { c = strip.Color(255,30,0,255);
        } else if (calEvent == "away") { c = strip.Color(108,105,128,255); }
    } else {
        // set as whatever color user controls via red and blue potentiometers
        int potRdgR = analogRead(potPinR);
        int potRdgB = analogRead(potPinB);
        int rVal = map(potRdgR,0,4095,0,255);
        int bVal = map(potRdgB,0,4095,0,255);
        
        c = strip.Color(rVal,120,bVal,255);
    }
    
}

int handleCalendarEvent(String eventType) {
    if (eventType != "") { shouldChangeColor = true;
    } else { shouldChangeColor = false; }
    calEvent = eventType;
    
    if (shouldChangeColor) { return 1; }
    return -1;
}
Click to Expand

Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!

0