#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
#include <Countimer.h>
Countimer timer;
int rpm = 0;
int time_left = 30; //this is in minutes
int rcf = 0;
int rcfmg = 0;
int time_set = 30;
char key = ' ';
LiquidCrystal_I2C lcd(0x27, 16, 4);
const int ROW_NUM = 4;
const int COLUMN_NUM = 4;
char keys[ROW_NUM][COLUMN_NUM] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte pin_rows[ROW_NUM] = {6, 7, 8, 12};
byte pin_column[COLUMN_NUM] = {2, 3, 4, 5};
Keypad keypad = Keypad(makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COLUMN_NUM);
void lcd_form1(){
//lcd.clear();
lcd.setCursor(0, 0);
lcd.print("SPEED: ");
lcd.print(rpm);
lcd.print("%");
lcd.setCursor(11, 0);
lcd.print("TIME: ");
time_left =timer.getCurrentSeconds();
lcd.print(time_left);
lcd.print("s ");
lcd.setCursor(0,2);
lcd.print("RCF:");
lcd.print(rcf);
lcd.print("g");
lcd.setCursor(11,2);
lcd.print("RCFmg:");
lcd.print(rcfmg);
lcd.print("mg");
lcd.setCursor(11,2);
}
void onComplete(){
lcd.setCursor(5,3);
lcd.print("Timer DONE!!!");
delay(100);
lcd.clear();
lcd.setCursor(5,3);
lcd.print("Timer DONE!!!");
delay(2000);
lcd.clear();
}
void setup() {
Serial.begin(9600);
lcd.init();
lcd.backlight();
lcd.print("Initializing");
delay(1000);
lcd.clear();
timer.setCounter(0, 0, time_set, timer.COUNT_DOWN, onComplete); // sample timer
timer.setInterval(refreshClock, 1000);
timer.run();
}
void refreshClock() {
Serial.print("Current count time is: ");
Serial.println(timer.getCurrentTime());
}
void keypad_func(){
switch(key){
case 'A':
// start
timer.start();
Serial.println("timer has started");
break;
case 'B':
//stop
timer.stop();
Serial.println("timer has been stopped");
break;
default:
// statements
break;
}
}
void loop() {
key = keypad.getKey();
timer.run();
if (key != NO_KEY){
lcd.setCursor(0, 3); //just to monitor the lates pressed keypad
lcd.print(key);
keypad_func();
}
lcd_form1();
}