//Device 1
#include "Particle.h"
#include <neopixel.h>
#include <iostream>
#include <string>
#define PIXEL_PIN SPI
#define PIXEL_COUNT 8
#define PIXEL_TYPE WS2812
int windSensorPin = A0;
int windSpeed = 0; //range:1700-2400
int threshold = 2000;
unsigned long lastFade = 0;
int Interval = 3000;
int buttonPin = D1;
int redValue = 255;
int greenValue = 255;
int blueValue = 255;
int color = 255;
int breathecount = 0;
bool buttonsignal = true;
int delayvalue = 5;
int largerthanthresholdcount = 0;
Adafruit_NeoPixel strip(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
uint16_t i;
uint32_t c = strip.Color(0, 0, 0);
void setup() {
Serial.begin( 9600 );
strip.begin();
strip.show();
Particle.variable("speed",&windSpeed, INT);
pinMode( buttonPin , INPUT_PULLUP);
}
void loop() {
windSpeed = analogRead(windSensorPin);
int buttonState = digitalRead( buttonPin );
while( buttonState == LOW ){
windSpeed = analogRead(windSensorPin);
if (windSpeed>threshold){
buttonsignal = false;
Secondstagebreathe();
}
if(buttonsignal == true){
Firststagesignal();
}
buttonState = digitalRead( buttonPin );
}
if(buttonsignal == false){
if(breathecount>0){
for(i=0;i<3;i++){
Sendsuccessfully();
delay(50);
}
buttonsignal = true;
char breathe[10];
itoa(breathecount, breathe, 10);
Particle.publish("kissPublish",breathe);
}
}
breathecount = 0;
}
void Firststagesignal(){
for(i=0; i< strip.numPixels(); i++) {
c = strip.Color(redValue, 0, 0);
strip.setPixelColor(i, c );
strip.show();
delay( 5 );
}
for(i=0; i< strip.numPixels(); i++) {
c = strip.Color(0, 0, 0);
strip.setPixelColor(i, c );
strip.show();
delay( 5 );
}
}
void delayvariation(){
windSpeed = analogRead(windSensorPin);
delay(5);
if(windSpeed){
}
}
void Secondstagebreathe(){
c = strip.Color(255, 255, 255);
if (windSpeed>threshold){
unsigned long now = millis();
c = strip.Color(0, 0, 0);
if ((now - lastFade) >= Interval) {
for (int color = 0; color < 255; color++) {
for (i = 0; i < strip.numPixels(); i++) {
c = strip.Color(color, color, color);
strip.setPixelColor(i, c);
}
strip.show();
delay(delayvalue);
}
for (int color = 255; color > 0; color--) {
for (i = 0; i < strip.numPixels(); i++) {
c = strip.Color(color, color, color);
strip.setPixelColor(i, c);
}
strip.show();
delay(delayvalue);
}
lastFade = now;
}
breathecount ++;
Serial.println(breathecount);
}
}
void Sendsuccessfully(){
//blink green lights
uint16_t i;
uint32_t c = strip.Color(0, 0, 0);
for(i=0; i< strip.numPixels(); i++) {
c = strip.Color(0, greenValue, 0);
strip.setPixelColor(i, c );
strip.show();
delay( 10 );
}
for(i=0; i< strip.numPixels(); i++) {
c = strip.Color(0, 0, 0);
strip.setPixelColor(i, c );
strip.show();
delay( 10 );
}
}
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. .