Back to Parent

//For button two
// This #include statement was automatically added by the Particle IDE.
#include "lib1.h"
// This #include statement was automatically added by the Particle IDE.
#include <neopixel.h>
//PopupBox
/*
subscribed to listen to button presses
when button pressed, led and solenoid turn off, for other button, led and solenoid turn on
*/
#define PIXEL_PIN D6
#define PIXEL_COUNT 16
#define PIXEL_TYPE WS2812B
int solOne = D12;
int button = D3;
int buttonOneState = 0;
Adafruit_NeoPixel strip(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
void setup() {
   Particle.subscribe("buttonTwo", myHandler);
   pinMode(solOne, OUTPUT);
   pinMode(button, INPUT);
   turnOn();
   strip.begin();
   strip.show();
}
void loop() {
   buttonOneState = digitalRead(button);
   //publish buttonState as solone t or f
   if (buttonOneState == HIGH){
       Particle.publish("buttonOne","pressed",PUBLIC);
       digitalWrite(solOne, HIGH);
       turnOff();
   }
   else{
   }
   delay(100);
}
// Now for the myHandler function, which is called when the cloud tells us that our buddy's event is published.
void myHandler(const char *event, const char *data)
{
   if (strcmp(data,"pressed")==0) {
       digitalWrite(solOne, LOW);
       turnOn();
   }
 else {
   // if the data is something else, don't do anything.
   // Really the data shouldn't be anything but those two listed above.
 }
}
void turnOn()
{
   for(uint16_t i=0; i< strip.numPixels(); i++) {
       strip.setPixelColor(i, strip.Color(255, 255, 0));
   }
   strip.show();
}
void turnOff()
{
   for(uint16_t i=0; i< strip.numPixels(); i++) {
     strip.setPixelColor(i, 0, 0, 0);
   }
   strip.show();
}
Click to Expand

Content Rating

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

0