// This #include statement was automatically added by the Particle IDE.
#include <HC_SR04.h>
double cm = 0.0;
bool beam_status = false;
int trigPin = D4;
int echoPin = D5;
int led_pin_b = A0;
int led_pin_w = A1;
HC_SR04 rangefinder = HC_SR04(trigPin, echoPin);
void setup() {
Spark.variable("cm", &cm, DOUBLE);
pinMode(led_pin_b,OUTPUT);
pinMode(led_pin_w,OUTPUT);
}
void loop() {
cm = rangefinder.getDistanceCM();
if (cm<15 ){
digitalWrite(led_pin_b,LOW);
digitalWrite(led_pin_w,HIGH);
}
else if (cm>15 && cm<30){
digitalWrite(led_pin_w,LOW);
digitalWrite(led_pin_b,HIGH);
}
else if(cm>30) {
digitalWrite(led_pin_b,LOW);
digitalWrite(led_pin_w,LOW);
}
delay(100);
}
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. .