Back to Parent

// This #include statement was automatically added by the Particle IDE.
#include <neopixel.h>

// Include Particle Device OS APIs
#include "Particle.h"
// VARIABLES
#define PIXEL_PIN SPI // plug into pin MO
#define PIXEL_COUNT 7 // 0 addressed
//#define PIXEL_TYPE SK6812RGBW
#define PIXEL_TYPE WS2812B

int buttonPin = D3;
 

// Let Device OS manage the connection to the Particle Cloud
SYSTEM_MODE(AUTOMATIC);

// Show system, cloud connectivity, and application logs over USB
// View logs with CLI using 'particle serial monitor --follow'
SerialLogHandler logHandler(LOG_LEVEL_INFO);


Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);

unsigned long buttonPress = 0;
unsigned long now;
bool buttonHold = FALSE;
int buttonState;

uint32_t w = strip.Color(0, 0, 0, 255); // Pure white
uint32_t c1 = strip.Color(0, 0, 255); // Blue
uint32_t c2 = strip.Color(0, 255, 0); // Green
    
// setup() runs once, when the device is first turned on
void setup() {
    Particle.function("notify",led_notification);
    strip.begin();
    pinMode( buttonPin , INPUT_PULLUP);
    Particle.variable("button", buttonState);
    Particle.variable("hold", buttonHold);
    Particle.variable("now", now);
    Particle.variable("now", buttonPress);
    
}

// loop() runs over and over again, as quickly as it can execute.
void loop() {
    
    now = millis();
    buttonState = digitalRead( buttonPin );
    
    //Check how long button is pressed
    if (buttonState == LOW && buttonHold == FALSE){
        buttonHold = TRUE;
        buttonPress = now;
    }else if (buttonState == LOW && buttonHold == TRUE){
        if((now - buttonPress) >= 3000){
            for( int i = 0; i < strip.numPixels(); i++ ){
                strip.setPixelColor(i,w); // set a color 
                strip.show();
            }
            
        }
    }else{
        buttonHold = FALSE;
    }
    
    
}


//function do display to LED strip when there is a notification
int led_notification(String command){
     
    for( int i = 0; i < strip.numPixels(); i++ ){
        strip.setPixelColor(i, c1); // set a color 
        strip.show();
        delay( 100 );
    }
    for( int i = 0; i < strip.numPixels(); i++ ){
        strip.setPixelColor(i, c2); // set a color 
        strip.show();
        delay( 100 );
    }
    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