Add seond sensor
This commit is contained in:
parent
6db53bfdee
commit
039e4758f1
1 changed files with 16 additions and 5 deletions
|
|
@ -1,22 +1,33 @@
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <SharpIR.h>
|
#include <SharpIR.h>
|
||||||
|
|
||||||
SharpIR sensor(SharpIR::GP2Y0A02YK0F, A0);
|
SharpIR sensorProx(SharpIR::GP2Y0A02YK0F, A0);
|
||||||
|
SharpIR sensorDown(SharpIR::GP2Y0A02YK0F, A1);
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
pinMode(A0, INPUT);
|
pinMode(A0, INPUT);
|
||||||
// put your setup code here, to run once:
|
pinMode(A1, INPUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
int distance = sensor.getDistance();
|
int distanceProx = sensorProx.getDistance();
|
||||||
|
int distanceDown = sensorDown.getDistance();
|
||||||
|
Serial.print("Proximity");
|
||||||
|
Serial.println(distanceProx);
|
||||||
|
Serial.print("Down");
|
||||||
|
Serial.println(distanceDown);
|
||||||
|
delay(100);
|
||||||
|
|
||||||
if (distance < 40)
|
if (distanceProx < 40)
|
||||||
{
|
{
|
||||||
Serial.println("isWithinThreshhold");
|
Serial.println("Through first barrier");
|
||||||
|
}
|
||||||
|
if (distanceDown < 35)
|
||||||
|
{
|
||||||
|
Serial.println("Through second barrier");
|
||||||
}
|
}
|
||||||
delay(100);
|
delay(100);
|
||||||
}
|
}
|
||||||
Reference in a new issue