Here's the code as it is now:
Code: Select all
#include <LiquidCrystal.h>
LiquidCrystal lcd(7,8,9,10,11,12);
const int buttonPin2 = 3; // the pin that the Up pushbutton is attached to
const int buttonPin3 = 4; // the pin that the Down pushbutton is attached to
const int buttonPin = 5; // the pin that the Up pushbutton is attached to
const int buttonPin1 = 6; // the pin that the Down pushbutton is attached to
// Variables will change:
int button2PushCounter = 0; // counter for the number of button presses
int buttonState3 = 0; // current state of the button
int buttonState4 = 0; // current state of the button
int lastButton2State = 0; // previous state of the button
int buttonPushCounter = 0; // counter for the number of button presses
int buttonState5 = 0; // current state of the button
int buttonState6 = 0; // current state of the button
int lastButtonState = 0; // previous state of the button
void setup() {
// initialize the button pin as a input:
pinMode(buttonPin, INPUT);
pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
pinMode(buttonPin3, INPUT);
lcd.begin(16,2);
lcd.setCursor(0,0);
lcd.print("PadCutOff:");
lcd.setCursor(0,1);
lcd.print("MaxPlTime:");
}
void loop() {
// read the pushbutton up input pin:
buttonState3 = digitalRead(buttonPin3);
// compare the buttonState to its previous state
if (buttonState3 != lastButton2State) {
// if the state has changed, increment the counter
if (buttonState3 == HIGH)
{
button2PushCounter++;
lcd.setCursor(10,1);
lcd.print(button2PushCounter);
}
delay(50);
}
// save the current state as the last state,
//for next time through the loop
lastButton2State = buttonState3;
// read the pushbutton down input pin:
buttonState4 = digitalRead(buttonPin2);
// compare the buttonState to its previous state
if (buttonState4 != lastButton2State) {
// if the state has changed, decrement the counter
if (buttonState4 == HIGH)
{
--button2PushCounter;
lcd.setCursor(10,1);
lcd.print(button2PushCounter);
}
delay(50);
}
// read the pushbutton up input pin:
buttonState5 = digitalRead(buttonPin);
// compare the buttonState to its previous state
if (buttonState5 != lastButtonState) {
// if the state has changed, increment the counter
if (buttonState5 == HIGH)
{
buttonPushCounter++;
lcd.setCursor(10,0);
lcd.print(buttonPushCounter);
}
delay(50);
}
// save the current state as the last state,
//for next time through the loop
lastButtonState = buttonState5;
// read the pushbutton down input pin:
buttonState6 = digitalRead(buttonPin1);
// compare the buttonState to its previous state
if (buttonState6 != lastButtonState) {
// if the state has changed, decrement the counter
if (buttonState6 == HIGH)
{
--buttonPushCounter;
lcd.setCursor(10,0);
lcd.print(buttonPushCounter);
}
delay(50);
if (buttonPushCounter < 126)
{
lcd.setCursor(13,0);
lcd.print(" ");
}
if (buttonPushCounter <= 0)
{
lcd.setCursor(13,0);
lcd.print("OFF");
buttonPushCounter=0;
}
if (buttonPushCounter >= 126)
{
lcd.setCursor(13,0);
lcd.print("Max");
buttonPushCounter=126;
}
}
if (button2PushCounter < 126)
{
lcd.setCursor(13,1);
lcd.print(" ");
}
if (button2PushCounter <= 0)
{
lcd.setCursor(13,1);
lcd.print("OFF");
button2PushCounter=0;
}
if (button2PushCounter >= 126)
{
lcd.setCursor(13,1);
lcd.print("Max");
button2PushCounter=126;
}
// save the current state as the last state,
//for next time through the loop
lastButtonState = buttonState6;
lastButton2State = buttonState4;
}
Any suggestions ?
Thank you in advance.