I recently purchased an arduino for a project I’m building. I have no prior knowledge of coding, but I’m learning. Im building a custom tv mount with a linear actuator and 2 DC motors that are controlled via IR. The build has 7 Micro switches acting as limits, and 6 push buttons in case the IR fails at some point. I have everything working for the manual controls via momentary push buttons and IR. Everything is wired to a port on my Mega. All of the circuits are opened and closed via the arduino.
My problem: I’m trying to write sequences for different positions of the tv.
For example, Position one would check the status of limit switch 1, 3, and 6. If they are all pressed, then the actuator would lower until limit switch 2 is pressed. Then it would turn the DC motor 1 clockwise until limit switch 4 is pressed, then dc motor 2 clockwise until limit switch 7 is pressed.
If Limit switch 2 is already closed and Limit switch 1 is open, then i would like it to proceed to the next step in that sequence. So it would look something like this:
void loop() {
if(digitalRead(LS1) == LOW
&& digitalRead(LS2) == HIGH
&& digitalRead(LS3) == LOW
&& digitalRead(LS4) == HIGH
&& digitalRead(LS5) == HIGH
&& digitalRead(LS6) == LOW
&& digitalRead(LS7) == HIGH)
({digitalWrite(relay1, LOW));
while(LS2)=HIGH));
digitalWrite(relay3, LOW);
while (LS4)=HIGH);
digitalWrite(relay4,LOW);
while (LS7)=HIGH);}
else if(digitalRead(LS1) == HIGH
&& digitalRead(LS2) == LOW
&& digitalRead(LS3) == LOW
&& digitalRead(LS4) == HIGH
&& digitalRead(LS5) == HIGH
&& digitalRead(LS6) == LOW
&& digitalRead(LS7) == HIGH)
digitalWrite(relay3, LOW);
while (LS4)=HIGH);
digitalWrite(relay4,LOW);
while (LS7)=HIGH);}
That code is showing errors at the moment. Im still having some trouble with bracket placements, but it should get the general idea across. It seems like there should be a much better way to write this. It's probably been answered before, but i don't really know what to search for.