Back to Parent

int ledPin = D0; // set up led
int rangefinder = A0; // set up rangefinder

void setup() {
  pinMode( ledPin , OUTPUT ); // set led as output
  pinMode(rangefinder, INPUT); // set rangefinder as input

//subsribe to the box open event from other Particle
  Particle.subscribe("diot2016/bcj/open", lightled);
  Serial.begin(9600); //serial to check range finder read
}
void loop()
{
  //read range finder
  int hand = analogRead(rangefinder);

  // serial print range finder read
  Serial.println(hand);

  // if the range finder sees something in front of the picture frame...
  if (hand >= 50)
  {
    Particle.publish( "diot2016/bcj/wave");{ //publish event to channel
    delay(1000);
  }

  }
}

void lightled(const char *event, const char *data) //set function for lighting LED
{
  digitalWrite(ledPin, HIGH); //turn led on
  delay(1000); //delay 1 second
  digitalWrite(ledPin, LOW); // turn led off
}
Click to Expand

Content Rating

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

0