[Solved] My program has no error codes, but not working

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;
  } 
}

Am I missing something or did I forget something?

Yes. You forget to say what the code actually does and how that differs from what you intended.

I suspect the title of this thread describes 50% of all programs ever written.

The UK health service spent £billions (literally) on one of them. :slight_smile:

...R

Get some feedback.
You could do that by adding a LED and a resistor wired to a free pin, plus by using pin 13, which is supposed to have its own LED attached on the board.
Have the LEDs lit or not by your sketch.
You could as well connect 2 LEDs to the motor pins (instead of the motor (controller)).