Back to Parent

//Baby Photon

int ledPin = 0;
int button_pin = D1;
int blink_delay;
int reps;
int buttonPin = D1;
int button_pressed = 0;


void setup ()
{
  pinMode(ledPin, OUTPUT);
  pinMode(button_pin, INPUT_PULLUP);
  pinMode(D7, OUTPUT);
  Particle.subscribe("bz/motion_detect_on", alarm_light_on);
  Particle.subscribe("bz/motion_detect_off", alarm_light_off);
  /*Particle.variable("button_pressed", &button_pressed, INT);*/


  /*digitalWrite(D7, HIGH);*/

}

void loop()
{
int buttonState = digitalRead( buttonPin );

if( buttonState == LOW )
  {
    // turn the alarm On
    if ( button_pressed ==0)
      Particle.publish("bz/button","push");
    int button_pressed = 1;
  }else{
    // otherwise
    // turn the LED Off
    digitalWrite( ledPin, LOW);
    button_pressed = 0;
  }





}





int blinking(int ledPin, int blink_delay, int reps)
{
  pinMode( ledPin, OUTPUT);
  for (int i =1; i <= reps; i++)
  {
    digitalWrite( ledPin, HIGH);
    delay(blink_delay);
    digitalWrite( ledPin, LOW);
    delay(blink_delay);
  }

  return 1;
}

void alarm_light_on(const char *event, const char *data)
{
  digitalWrite(ledPin, HIGH);
  delay(5000);

}

void alarm_light_off(const char *event, const char *data)
{
  digitalWrite(ledPin, LOW);
  delay(50);

}
Click to Expand

Content Rating

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

0