Code: Select all
Code: Select all
//
//Compatible with the Arduino IDE 1.0
//Library version:1.1
#include <Wire.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
// this constant won't change:
const int Up_buttonPin1 = 6; // the pin that the pushbutton is attached to
const int Up_buttonPin2 = 7;
// Variables will change:
int buttonPushCounter1 = 0; // counter for the number of button presses
int up_buttonState1 = 0; // current state of the up button
int up_lastButtonState1 = 0; // previous state of the up button
int buttonPushCounter2 = 0; // counter for the number of button presses
int up_buttonState2 = 0; // current state of the up button
int up_lastButtonState2 = 0; // previous state of the up button
int down_buttonState1 = 0; // current state of the up button
int down_lastButtonState1 = 0; // previous state of the up button
bool bPress1 = false;
int down_buttonState2 = 0; // current state of the up button
int down_lastButtonState2 = 0; // previous state of the up button
bool bPress2 = false;
void setup()
{
Serial.begin(9600);
pinMode( Up_buttonPin1 , INPUT_PULLUP);
pinMode( Up_buttonPin2, INPUT_PULLUP);
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.setCursor(0,0);
lcd.print("Home Visitor");
lcd.setCursor(12,2);
lcd.print(buttonPushCounter1);
lcd.setCursor(2,2);
lcd.print(buttonPushCounter2);
}
void loop()
{
checkUp1();
checkUp2();
if( bPress1){
bPress1 = false;
lcd.setCursor(0,0);
lcd.print("Home Visitor");
lcd.setCursor(12,2);
lcd.print(buttonPushCounter1);
}
if( bPress2){
bPress2 = false;
lcd.setCursor(0,0);
lcd.print("Home Visitor");
lcd.setCursor(2,2);
lcd.print(buttonPushCounter2);
}
}
void checkUp1()
{
up_buttonState1 = digitalRead(Up_buttonPin1);
// compare the buttonState to its previous state
if (up_buttonState1 != up_lastButtonState1) {
// if the state has changed, increment the counter
if (up_buttonState1 == LOW) {
bPress1 = true;
// if the current state is HIGH then the button went from off to on:
buttonPushCounter1++;
Serial.println("on");
Serial.print("number of button pushes: ");
Serial.println(buttonPushCounter1);
} else {
// if the current state is LOW then the button went from on to off:
Serial.println("off");
}
// Delay a little bit to avoid bouncing
delay(50);
}
// save the current state as the last state, for next time through the loop
up_lastButtonState1 = up_buttonState1;
}
void checkUp2()
{
up_buttonState2 = digitalRead(Up_buttonPin2);
// compare the buttonState to its previous state
if (up_buttonState2 != up_lastButtonState2) {
// if the state has changed, increment the counter
if (up_buttonState2 == LOW) {
bPress2 = true;
// if the current state is HIGH then the button went from off to on:
buttonPushCounter2++;
Serial.println("on");
Serial.print("number of button pushes: ");
Serial.println(buttonPushCounter2);
} else {
// if the current state is LOW then the button went from on to off:
Serial.println("off");
}
// Delay a little bit to avoid bouncing
delay(50);
}
// save the current state as the last state, for next time through the loop
up_lastButtonState2 = up_buttonState2;
}