#include <Keypad.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);
int kdelay = 50;
int period = 0;
int LED=13;
const int trigPin = 11;
const int echoPin = 10;
long duration;
int distanceCm, distanceInch;
int cursorColumn = 0;
const byte ROWS = 4;
const byte COLS = 4;
char BufNum[8];
char hexaKeys[COLS][ROWS] =
{
{ '1','4','7','*' },
{ '2','5','8','0' },
{ '3','6','9','#' },
{ 'A','B','C','D' }
};
byte rowPins[ROWS] = { 5, 4, 3, 2 };
byte colPins[COLS] = { 9, 8, 7, 6 };
Keypad kpd = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
String v1;
String v2;
void setup()
{
lcd.init();
lcd.backlight();
Serial.begin(9600);
pinMode(LED, OUTPUT);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop()
{
//v1 = GetNumber();
//int Val = v1.toInt();
lcd.setCursor(0,0);
lcd.print("Setlevel:");
lcd.setCursor(0,1);
lcd.print("Water level:");
lcd.setCursor(0,2);
lcd.print("Humidity:");
//lcd.setCursor(0,3);
//lcd.print("Motor stt:");
//lcd.setCursor(12,2);
//lcd.print(Val);
//========================================================================
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(11);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distanceCm = duration * 0.034 / 2;
distanceInch = duration * 0.0133 / 2;
lcd.setCursor(12,1);
lcd.print(distanceCm);
lcd.print(" cm");
delay(10);
//========================================================================
if (distanceCm<100)
{
digitalWrite(LED,HIGH);
}
else
{
digitalWrite(LED,LOW);
}
//========================================================================
char key = kpd.getKey();
if (key)
{
lcd.setCursor(cursorColumn,0); // move cursor to (cursorColumn, 0)
lcd.print(key); // print key at (cursorColumn, 0)
cursorColumn++; // move cursor to next position
if(cursorColumn == 4)
{
lcd.clear();
cursorColumn = 0;
}
}
}
//========================================================================
/*String GetNumber()
{
String num;
char key = kpd.getKey();
lcd.setCursor(0,0);
lcd.print("Setlevel:");
while(key != '#')
{
switch (key)
{
case NO_KEY:
break;
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
lcd.print(key);
num = num +key;
break;
case '*':
num = "";
lcd.clear();
break;
}
key = kpd.getKey();
}
return num;
}*/
//========================================================================