Hi, I am trying to rewrite an old program of mine so its a little neater. I am not getting any obvious errors, but it still does not work as intended. Am I missing something or did I forget something? The program just reads a analog sensor and controls two motors. I don't think the two functions LeftSensor and RightSensor are returning a values. When the IR sensor detects something it should make sensePin1 go below 150. The two functions should return a 1 when a object is detected, making the Lmotor or Rmotor go LOW. Sorry I see what I did wrong thanks anyways.
Thanks, Jeff
#define sensePin1 5
#define Lmotor 9
#define Rmotor 8
void setup()
{
analogReference(DEFAULT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(Lmotor, OUTPUT);
pinMode(Rmotor, OUTPUT);
pinMode(A5, INPUT);
}
void loop()
{
if (LeftSensor() == 1)
{
digitalWrite(Lmotor, LOW);
}
else
{
digitalWrite(Lmotor, HIGH);
}
if (RightSensor() == 1)
{
digitalWrite(Rmotor, LOW);
}
else
{
digitalWrite(Rmotor, HIGH);
}
}
int LeftSensor()
{
digitalWrite(3, HIGH);
int val1 = analogRead(sensePin1);
delay(10);
if(val1 < 150)
{
return 1;
}
else
{
return 0;
}
}
int RightSensor()
{
digitalWrite(4, HIGH);
int val2 = analogRead(sensePin1);
delay(10);
if(val2 < 150)
{
return 1;
}
else
{
return 0;
}
}