Kindly help in debug this code. The code is to control four servos in an angle given with four push bottons.
#include <Servo.h>
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int button1=0;
int button2=0;
int button3=0;
int button4=0;
Servo myservo1;
Servo myservo2;
Servo myservo3;
Servo myservo4;
float pos = 0;
void setup() {
myservo1.attach(6);
myservo2.attach(7);
myservo3.attach(8);
myservo4.attach(9);
pinMode(A0, INPUT);
pinMode(A1, INPUT);
pinMode(A2, INPUT);
pinMode(A3, INPUT);
// set up the LCD's number of columns and rows:
lcd.begin(12, 2);
// Print a message to the LCD.
lcd.setCursor(4, 0);
lcd.print("WELCOME");
delay(1000);
lcd.clear();
lcd.setCursor(2, 0);
lcd.print("INITIALIZING");
lcd.setCursor(1, 2);
lcd.print("PLEASE WAIT...");
delay(100);
lcd.clear();
delay(100);
lcd.noCursor();
delay(100);
lcd.setCursor(2, 0);
lcd.print("SYSTEM READY");
delay(100);
lcd.clear();
}
void loop()
{
//code for fist button begins
button1=digitalRead(A0);
if(button1==HIGH)
{
for(pos; pos < 90&&button1==HIGH; pos +=2)
{
myservo1.write(pos);
delay(15);
button1=digitalRead(A0);
}
lcd.print("FILLED BUCKET 1");
}
if(button1==LOW)
lcd.print("FILLING BUCKET 1");
{
for(pos; pos>=0&&button1==LOW; pos-=2)
{
myservo1.write(pos);
delay(15);
button1=digitalRead(A0);
}
}
//code for fist button ends
//code for second button begins
button2=digitalRead(A1);
if(button2==HIGH)
{
for(pos; pos < 90&&button2==HIGH; pos +=2)
{
myservo2.write(pos);
delay(15);
button2=digitalRead(A1);
}
lcd.print("FILLED BUCKET 1");
}
if(button2==LOW)
lcd.print("FILLING BUCKET 1");
{
for(pos; pos>=0&&button2==LOW; pos-=2)
{
myservo2.write(pos);
delay(15);
button2=digitalRead(A1);
}
}
//code for second button ends
//code for Third button begins
button3=digitalRead(A1);
if(button3==HIGH)
{
for(pos; pos < 90&&button3==HIGH; pos +=2)
{
myservo3.write(pos);
delay(15);
button3=digitalRead(A2);
}
lcd.print("FILLED BUCKET 1");
}
if(button3==LOW)
lcd.print("FILLING BUCKET 1");
{
for(pos; pos>=0&&button3==LOW; pos-=2)
{
myservo3.write(pos);
delay(15);
button3=digitalRead(A2);
}
}
//code for third button ends
//code for Fourth button begins
button4=digitalRead(A3);
if(button4==HIGH)
{
for(pos; pos < 90&&button4==HIGH; pos +=2)
{
myservo4.write(pos);
delay(15);
button4=digitalRead(A3);
}
lcd.print("FILLED BUCKET 1");
}
if(button4==LOW)
lcd.print("FILLING BUCKET 1");
{
for(pos; pos>=0&&button4==LOW; pos-=2)
{
myservo4.write(pos);
delay(15);
button4=digitalRead(A3);
}
}
//code for fourth button ends
}
//end of void loop