// Device 2
#include "Particle.h"
#include <neopixel.h>
#define PIXEL_PIN SPI
#define PIXEL_COUNT 8
#define PIXEL_TYPE WS2812
Adafruit_NeoPixel strip(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
uint16_t i;
uint32_t c = strip.Color(0, 0, 0);
int buttonPin = D2;
unsigned long lastFade = 0;
int Interval = 3000;
bool receive_or_not = false;
bool signall = true;
int breathecountreceive = 0;
int buttonState = digitalRead( buttonPin );
void setup(){
strip.begin();
strip.show();
Particle.subscribe("kissReceive", handlekiss);
Serial.begin( 9600 );
}
void handlekiss(const char *event, const char *data) {
breathecountreceive = atoi(data);
receive_or_not = true;
}
void loop(){
Serial.println(breathecountreceive);
Serial.println(receive_or_not);
Serial.println(buttonState);
buttonState = digitalRead( buttonPin );
if(receive_or_not == true){
if (signall == true){
for(i=0 ;i < breathecountreceive;i++){
Secondstagebreathe();
}
// for( i = 0;i<3;i++){
// Receivepinksignal();
// }
}
signall = false;
// else if (buttonState==LOW){
// for(i=0;i<breathecountreceive;i++){
// Secondstagebreathe();
// }
// signall = false;
// }
}
delay(500);
}
void Receivepinksignal(){
for(i=0; i< strip.numPixels(); i++) {
c = strip.Color(0, 0, 255);
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 Secondstagebreathe(){
c = strip.Color(255, 255, 255);
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(5);
}
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(5);
}
lastFade = now;
}
}
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. .