/*This program will alert the user that there is an increase in incoming emails
through lights and speed of a neopixel, it can be reset by pushing a button*/
#include "neopixel.h"
#include <math.h>
// IMPORTANT: Set pixel COUNT, PIN and TYPE
#define PIXEL_PIN D0
#define PIXEL_COUNT 24
#define PIXEL_TYPE WS2812B
int status = 0;
int pixel_position = 0;
int btnState = LOW;// initialize the button
int btn = D1;//Led btn
//No new emails, breathe
// IMPORTANT: Set pixel COUNT, PIN and TYPE
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
void setup() {
Serial.begin( 9600 );
strip.begin();
strip.show(); // Initialize all pixels to 'off'
pinMode(btn, INPUT_PULLUP);
Particle.subscribe( "diot_breathe", emailcheck );
}
void loop() {
TurnOn();
if(status < 1){
breathe();
}
else if(1<=status<2){
colorchase();
}
else {fastcolorchase();
}
delay( 50 );
Serial.println (status);
}
void emailcheck(const char *event, const char *data){
status = status+1;
}
void TurnOn()
{
// find out if the button is pushed
// or not by reading from it.
int currentButtonState = digitalRead(btn);
if( currentButtonState == LOW && btnState != currentButtonState ){
status = 0;
}
btnState = currentButtonState;
}
/* Calc the sin wave for the breathing white led */
float breathe() {
float val = (exp(sin(millis()/2000.0*M_PI)) - 0.36787944)*108.0;
Serial.println( val );
uint16_t i;
uint32_t c = strip.Color(val, val, val);
for(i=0; i< strip.numPixels(); i++) {
strip.setPixelColor(i, c );
}
strip.show();
}
int colorchase() {
for(int i=0; i< strip.numPixels(); i++) {
uint32_t c;
if( pixel_position == i ){
c = strip.Color(50, 255, 10);
}else{
c = strip.Color(0, 0, 0);
}
strip.setPixelColor(i, c );
}
strip.show();
pixel_position++;
if( pixel_position >= strip.numPixels() )
{
pixel_position = 0;
}
}
int fastcolorchase() {
for(int i=0; i< strip.numPixels(); i++) {
uint32_t c;
if( pixel_position == i ){
c = strip.Color(255, 0, 0);
}else{
c = strip.Color(0, 0, 0);
}
strip.setPixelColor(i, c );
}
strip.show();
pixel_position++;
if( pixel_position >= strip.numPixels() )
{
pixel_position = 0;
}
}
//0 - 5 emails, increases by one dot for each email up to 5
//5+ emails, increase speed/change color
//Check emails, press button to reset*/
Click to Expand
Content Rating
Is this a good/useful/informative piece of content to include in the project? Have your say!
You must login before you can post a comment. .