need a little help

OK here is my program that I am having problems correcting this is my first program so bear with me. I am having a issue with the loop I think because I am using relays to control my motors to turn and the relays are cycling but I beleive its not going to the top of my program the Relays are two per side. The sensers are Left, Front, Right and when a object is detected they go low. I hope this is the correct syntax Thanks in advance! //Wall sensoning robot

//Pin Assignments int LS = 7; int FS = 1; int RS = 2; int M1A = 3; int M1B = 4; int M2A = 5; int M2B = 6;

//OUTPUT and INPUT Assignments void setup(){

pinMode(LS, INPUT); pinMode(FS, INPUT); pinMode(RS, INPUT); pinMode(M1A, OUTPUT); pinMode(M1B, OUTPUT); pinMode(M2A, OUTPUT); pinMode(M2B, OUTPUT); digitalWrite(M1A, LOW); digitalWrite(M1B, LOW); digitalWrite(M2A, LOW); digitalWrite(M2B, LOW); } void loop () { //Left sensor If Statement digitalRead(LS); if (LS = LOW)

digitalWrite(M2A, HIGH);

else digitalWrite(M2A, LOW);

//Right Sensor If Statement digitalRead(RS); if (RS = LOW)

digitalWrite(M1A, HIGH);

else digitalWrite(M1A, LOW);

{

//Front Sensor If Statement digitalRead(FS); if (FS = LOW)

digitalWrite(M1A, HIGH); digitalWrite(M1B, HIGH); digitalWrite(M2A, HIGH); digitalWrite(M2B, HIGH); delay (1000); digitalWrite(M1A, LOW); digitalWrite(M1B, LOW); delay (500); digitalWrite(M2A, LOW); digitalWrite(M2B, LOW);

else digitalWrite(M1A, LOW); digitalWrite(M1B, LOW); digitalWrite(M2A, LOW); digitalWrite(M2B, LOW); } }

This isn’t 1970s BASIC - you’re allowed to write meaningful variable names.

This:

if (LS = LOW)

is not the syntax you intended.
Try “==”.

Explanation: “=” is an assignment, in this case you’re assigning the value “LOW” to the variable “LS”, and testing the result.
Because “LOW” is the same as zero, and zero is always false, the result is always false.
[edit]A couple of things: “need a little help” is not a particularly useful title, and please use the “code” button (#) on the post editor’s toolbar when posting code.[/edit]

 digitalRead(FS);
 if (FS = LOW)

Even if you fix the if test, FS is a pin number. It will not be LOW. The digitalRead function returns a value that you throw away. It is that value that will be HIGH or LOW.

Oops yes, caught the mote, missed the plank!

Even if you fix the if test, FS is a pin number. It will not be LOW.

It will be LOW after the first pass through ! ;D

Which is another good reason for a) making the constant the left-hand side of a comparison b) making the pin number a "const" when it is declared.

So symatic/syntax aside, would you both agree that if yamR1 used

if (digitalRead(LS)==false)
{
     digitalWrite(M2A, HIGH);
}
  else 
{
  digitalWrite(M2A, LOW);
}

would give him the result he is looking for.? :)

Cheers Mark

The digitalRead function returns HIGH or LOW. The digitalWrite function expects HIGH or LOW as the 2nd argument.

All that is needed is:

digitalWrite(M2A, !digitalRead(LS));

PaulS
So pure…

Unfortunately for neewbies, this is kinda hard to grasp intially.

Mark B