Guys, thanks for the suggestions. I have tried to add the setcounter to be 0 when then condition has been satisfied and it seems to work!
I still can't find the attachment icon so I have to post the code in 2 posts again :~
But I have made the auto indent
#include <LiquidCrystal.h> // Include libraries
#include <Servo.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // initialize the library with the numbers of the interface pins
Servo myservo;
const int incrementPin = 6; // the pin that the increment pushbutton is attached to
const int setPin = 7; // the pin that the set pushbutton is attached to
int incrementPushButtonState = 0; // state of the increment pushbutton (low or high)
int setPushButtonState = 0; // state of the set pushbutton
int setCounter = 0; // no. of times set button is puched
int feedinterval = 1; // feedinterval counter range 2-4
int numberofdays = 0; // no. of days counter range 1-10
int firsthourvalue = 0; // first hour value range 1-2
int secondhourvalue = 0; // second hour value range 0-9
int firstminutevalue = 0; // first minute value range 1-5
int secondminutevalue = 0; // second minute value range 0-9
int servoposition = 0; // position of servo
int totalfeedforfeedinterval2 = 0;
int totalfeedforfeedinterval3 = 0;
int totalfeedforfeedinterval4 = 0;
void setup()
{
pinMode(incrementPin, INPUT); // initialize the button pin as a input:
pinMode(setPin, INPUT);
myservo.attach(9); // attaches the servo on pin 9 to the servo object
lcd.begin(20,4); // LCD has 20 columns, 4 rows
lcd.setCursor(0,0); // Choose column 0, row 0( 1st column, 1st row)
lcd.print("Freq: Days:"); // Print the stated
lcd.setCursor(0, 1); // Choose column 0, row 1
lcd.print("1st feed time:"); // Print the stated
lcd.setCursor (0, 2); // Choose column 0, row 2
lcd.print("current time:"); // Print the stated
lcd.setCursor(0,3); // Choose column 0, row 3
lcd.print(""); // Print the stated
lcd.setCursor(16,1); // Choose column 16, row 2
lcd.print(":"); // Print the stated
}
void loop()
{
{
setPushButtonState = digitalRead(setPin); // read the set pushbutton input pin:
if (setPushButtonState == HIGH) // if the pushbutton is pressed, high
{
if (setCounter > 6) // if pushbutton pressed more than 6 times, rollover to 0
{
setCounter = 0;
}
setCounter++; // counter increment by 1
if (setCounter == 1) // if counter is 1,
{
lcd.setCursor(5,0); // set LCD to column 5, row 0 and
lcd.blink(); // cursor blink
}
else
if (setCounter == 2) // if counter is 2, blink cursor at stated position
{
lcd.setCursor(15,0);
lcd.blink();
}
else
if (setCounter == 3) // if counter is 3, blink cursor at stated position
{
lcd.setCursor(14,1);
lcd.blink();
}
else
if (setCounter == 4) // if counter is 4, blink cursor at stated position
{
lcd.setCursor(15,1);
lcd.blink();
}
else
if (setCounter == 5) // if counter is 5, blink cursor at stated position
{
lcd.setCursor(17,1);
lcd.blink();
}
else
if (setCounter == 6) // if counter is 6, blink cursor at stated position
{
lcd.setCursor(18,1);
lcd.blink();
}
else
if (setCounter == 7) // if counter is 7, blinking stops
{
lcd.noBlink();
}
delay (1000);
}
if (setCounter == 1) // if set counter is 1
{
incrementPushButtonState = digitalRead (incrementPin); //read increment push button from increment pin
if (incrementPushButtonState == HIGH) // if push button is pressed (high)
{
lcd.setCursor (5,0); // set at 5th column, 0th row
lcd.blink();
feedinterval++; // feed interval increases by 1
lcd.setCursor (5,0);
lcd.print(feedinterval); // print value of freq
if (feedinterval > 4) // if freq value more than 4, reset to 2
{
feedinterval = 2;
lcd.setCursor (5,0);
lcd.print(feedinterval);
}
delay(300);
}
}
else if (setCounter == 2) // if set counter is 2
{
incrementPushButtonState = digitalRead (incrementPin); //perform same actions as for setCounter == 1
if (incrementPushButtonState == HIGH)
{
lcd.setCursor (15,0); // set at 15th column, 0th row
lcd.blink();
numberofdays++;
lcd.setCursor (15,0);
lcd.print(numberofdays); // print value of freq
if (numberofdays > 10) // if freq value more than 10, reset to 1
{
lcd.setCursor (15,0);
lcd.print (" "); // clears lcd character and specified position
numberofdays = 1;
lcd.setCursor (15,0);
lcd.print(numberofdays);
}
delay(300);
}
totalfeedforfeedinterval2 = numberofdays * 2;
totalfeedforfeedinterval3 = numberofdays * 3;
totalfeedforfeedinterval4 = numberofdays * 4;
}
else if (setCounter == 3) // if set counter is 3
{
incrementPushButtonState = digitalRead (incrementPin); //perform same actions as for setCounter == 1
if (incrementPushButtonState == HIGH)
{
lcd.setCursor (14,1); // set at 14th column, 1st row
lcd.blink();
firsthourvalue++;
lcd.setCursor (14,1);
lcd.print(firsthourvalue); // print value of freq
if (firsthourvalue > 2) // if freq value more than 2, reset to 1
{
firsthourvalue = 0;
lcd.setCursor (14,1);
lcd.print(firsthourvalue);
}
delay(300);
}
}
else if (setCounter == 4) // if set counter is 4
{
incrementPushButtonState = digitalRead (incrementPin); //perform same actions as for setCounter == 1
if (incrementPushButtonState == HIGH)
{
lcd.setCursor (15,1); // set at 15th column, 1st row
lcd.blink();
secondhourvalue++;
lcd.setCursor (15,1);
lcd.print(secondhourvalue); // print value of freq
if (secondhourvalue > 9) // if freq value more than 9, reset to 0
{
secondhourvalue = 0;
lcd.setCursor (15,1);
lcd.print (" ");
lcd.setCursor (15,1);
lcd.print(secondhourvalue);
}
delay(300);
}
}
else if (setCounter == 5) // if set counter is 5
{
incrementPushButtonState = digitalRead (incrementPin); //perform same actions as for setCounter == 1
if (incrementPushButtonState == HIGH)
{
lcd.setCursor (17,1); // set at 17th column, 1st row
lcd.blink();
firstminutevalue++;
lcd.setCursor (17,1);
lcd.print(firstminutevalue); // print value of freq
if (firstminutevalue > 5) // if freq value more than 5, reset to 0
{
firstminutevalue = 0;
lcd.setCursor (17,1);
lcd.print(firstminutevalue);
}
delay(300);
}
}