I currently have code written that increments and decrements a counter printed on an arduino 16x2 LCD display. I currently have one 3 prong SPDT swtich wired each to an input and the center pin grounded. When one side is triggered low(using pullup) it increases that temperature when the other side is low it decreases the temperature. I want to add in another digital switch, the function would be when this new switch is either high allow me to adjust the temperature. I need to be displaying the current temperature when the switch is low, and the new switch will be adjusting the set point not changing the current temperature. Please help.
#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
const byte up1 = 5; // the pin that the Up pushbutton is attached to
const byte down1 = 6; // the pin that the Down pushbutton is attached to
// Variables will change:
byte buttonPushCounter = 0; // counter for the number of button presses
byte buttonState5; // current state of the button
byte buttonState6; // current state of the button
byte lastButtonState = 0; // previous state of the button
void setup() {
pinMode(up1, INPUT_PULLUP);
pinMode(down1, INPUT_PULLUP);
lcd.begin(16, 2);
lcd.setCursor(7, 1);
lcd.print(0);
}
void loop() {
// read the pushbutton up input pin:
buttonState5 = digitalRead(up1);
// compare the buttonState to its previous state
if (buttonState5 != lastButtonState) {
// if the state has changed, increment the counter
if (buttonState5 == LOW)
{
buttonPushCounter++;
lcd.setCursor(7, 1);
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(down1);
// compare the buttonState to its previous state
if (buttonState6 != lastButtonState) {
// if the state has changed, decrement the counter
if (buttonState6 == LOW)
{
buttonPushCounter--;
lcd.setCursor(7, 1);
lcd.print(buttonPushCounter);
}
delay(50);
}
// save the current state as the last state,
//for next time through the loop
lastButtonState = buttonState6;
}