#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20 , 4);
// Generally, you should use "unsigned long" for variables that hold time
// The value will quickly become too large for an int to store
unsigned long previousMillis = 0; // will store last time LED was updated
unsigned long currentMillis = 0;
// constants won't change:
const long interval = 1000; // interval at which to blink (milliseconds)
const int buttonUpPin = 4; // the number of the pushbutton pin
const int buttonDownPin = 5; // the number of the pushbutton pin
const int buttonEscPin = 3; // the number of the pushbutton pin
const int buttonEnterPin = 2; // the number of the pushbutton pin
const byte ledPin = 13;
int upFlag = 0;
int downFlag = 0;
int escFlag = 0;
int enterFlag = 0;
int menuFlag = 0;
int displayMenuFlag = 0;
int buttonState; // the current reading from the input pin
int lastButtonState = LOW; // the previous reading from the input pin
// the following variables are unsigned longs because the time, measured in
// milliseconds, will quickly become a bigger number than can be stored in an int.
unsigned long lastDebounceTime = 0; // the last time the output pin was toggled
unsigned long debounceDelay = 50;
void setup()
{
lcd.init();
Serial.begin(115200);
lcd.begin(20, 4);
pinMode(ledPin, OUTPUT);
pinMode(buttonUpPin, INPUT_PULLUP);
pinMode(buttonDownPin, INPUT_PULLUP);
pinMode(buttonEscPin, INPUT_PULLUP);
pinMode(buttonEnterPin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(buttonDownPin), myDown, FALLING);
attachInterrupt(digitalPinToInterrupt(buttonUpPin), myUp, FALLING);
attachInterrupt(digitalPinToInterrupt(buttonEscPin), myEsc, FALLING);
attachInterrupt(digitalPinToInterrupt(buttonEnterPin), myEnter, FALLING);
}
int myTimer(int previous, int interval) {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
// save the last time you blinked the LED
previousMillis = currentMillis;
return 1;
}
return 0;
}
void displayTime(int time){
lcd.setCursor(0, 0);
lcd.print(" ");
lcd.setCursor(0, 0);
lcd.print(time / 1000);
}
void displayMenu(){
lcd.setCursor(0, 0);
lcd.print("CHOICE 1");
lcd.setCursor(0, 1);
lcd.print("CHOICE 2");
lcd.setCursor(0, 2);
lcd.print("CHOICE 3");
lcd.setCursor(0, 3);
lcd.print("CHOICE 4");
}
void displayFlag(){
lcd.setCursor(0, 0);
lcd.print(" ");
lcd.setCursor(0, 0);
if (upFlag) {
lcd.print("UP");
upFlag = 0;
}
if (downFlag) {
lcd.print("DOWN");
downFlag = 0;
}
if (escFlag) {
lcd.print("ESC");
menuFlag = 1;
escFlag = 0;
}
if (enterFlag) {
lcd.print("ENTER");
enterFlag = 0;
}
}
void myDown(){
downFlag = 1;
}
void myUp(){
upFlag = 1;
}
void myEsc(){
escFlag = 1;
}
void myEnter(){
enterFlag = 1;
}
int displayMenu(){
if
}
void loop() {
currentMillis = millis();
// Check state :
// on regarde si un flag est checké
// soit RUN et on est dans un programme
// soit MENU et on est en train de faire une séléction
//
if (isMenu()){
displayMenu();
}
else if(isRun()){
runProgram();
}
else
{
displayError();
}
if (menuFlag && !displayMenuFlag) {
displayMenuFlag = 0;
}
// if (digitalRead(buttonDownPin)) {
// downFlag = 1;
// displayFlag();
// }
// if (digitalRead(buttonUpPin)) {
// upFlag = 1;
// displayFlag();
// }
if (upFlag || downFlag || escFlag || enterFlag) {
displayFlag();
}
if (myTimer(previousMillis, interval) && !menuFlag) {
// if the LED is off turn it on and vice-versa:
displayTime(currentMillis);
}
}