#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
// set up a constant for the tilt switchPin
const int switchPin = 2;
static int hits = 0;
// variable to hold the value of the switchPin
int switchState = 0;
// variable to hold previous value of the switchpin
int prevSwitchState = 0;
void setup() {
lcd.init(); // Initialize the LCD
lcd.backlight(); //
// set up the number of columns and rows on the LCD
lcd.begin(16, 2);
// set up the switch pin as an input
pinMode(switchPin,INPUT);
Serial.begin(9600);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Hit the button");
lcd.setCursor(0, 1);
lcd.print("to increment");
}
void loop() {
// check the status of the switch
switchState = digitalRead(switchPin);
Serial.print("switchState:");Serial.println(switchState);
if (switchState != prevSwitchState) {
if (switchState == HIGH) {
hits = hits + 1;
delay(10);
}
}
Serial.print("hits:");Serial.println(hits);
if(hits==1)
{
Serial.println("hello");
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Help is en-route");
}else
if(hits==2)
{
Serial.println("welcome");
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("press is cancel");
}else
if ( hits>=3)
{
hits = 0;
Serial.println("couter is reset:");
}
Serial.println("...............");
delay(1000);
}