Anyone can help?
I have made some changes to my codes. But I am still having problem when I press the set pushbutton.
It works fine till it blinks at the LCD position (15,0) but after that when I press the increment pushbutton to increase the values at the dayscounter, it goes back to the freqcounter and increases it. So the program does not run the code for the daycounter..
Anyone can help? The code is:
#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 freqstate = 0; // state of the frequency pushbutton (low or high)
int setstate = 0;
int daystate = 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(1st column, last row)
lcd.print(""); // Print the stated
}
void loop()
{
for ( int freqcounter = 2; freqcounter < 5; freqcounter ++) // freq value from 2 to 4
{
freqstate = digitalRead (incrementPin);
if (freqstate == HIGH)
{
lcd.setCursor (5,0); // set at 5th column, 0th row
lcd.blink();
lcd.print(freqcounter); // print value of freq
if (freqcounter > 4) // if freq value more than 4, reset to 2
{
freqcounter = 2;
}
delay(300);
}
}
setstate = digitalRead(setPin); // read the pushbutton set input pin:
if (setstate == HIGH) // if the state has changed, increment the counter
{
lcd.setCursor(15,0);
lcd.blink();
for ( int daycounter = 1; daycounter < 11; daycounter ++) // freq value from 2 to 4
{
daystate = digitalRead (incrementPin);
if (daystate == HIGH)
{
lcd.setCursor (15,0); // set at 5th column, 0th row
lcd.blink();
lcd.print(daycounter); // print value of freq
if (daycounter > 10) // if freq value more than 4, reset to 2
{
daycounter = 1;
}
delay(300);
}
}
}
}