#include <Arduino.h>
#include "declarations.h"
#include "functions.h"
#include "Button.h"
#include "menu.h"
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <EEPROM.h>
void setup()
{
Serial.begin(9600);
pinMode(BTN_NEXT_PIN, INPUT_PULLUP);
pinMode(BTN_OK_PIN, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(BTN_NEXT_PIN), myISR1, CHANGE);
attachInterrupt(digitalPinToInterrupt(BTN_OK_PIN), myISR2, CHANGE);
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3c))
{
Serial.println(F("SSD1306 allocation failed"));
for (;;)
;
}
display.clearDisplay();
}
void myISR1()
{
static int countButtonInterrupt;
static long intervalButtonInterrupt;
static bool state;
if ((state == 0) && (digitalRead(BTN_NEXT_PIN) == LOW)) // front descendant
{
if (intervalButtonInterrupt > millis()) // anti rebond
return;
countButtonInterrupt++;
okBtn.SetCount(&countButtonInterrupt);
state = 1;
}
else if ((state == 1) && (digitalRead(BTN_NEXT_PIN) == HIGH)) // remontant
{
intervalButtonInterrupt = millis() + 50; // delay
state = 0;
}
}
void myISR2()
{
static long intervalButtonInterrupt;
static int countButtonInterrupt;
static bool state;
if ((state == 0) && (digitalRead(BTN_OK_PIN) == LOW)) // front descendant
{
if (intervalButtonInterrupt > millis()) // anti rebond
return;
countButtonInterrupt++;
nextBtn.SetCount(&countButtonInterrupt);
state = 1;
}
else if ((state == 1) && (digitalRead(BTN_OK_PIN) == HIGH)) // remontant
{
intervalButtonInterrupt = millis() + 50; // delay
state = 0;
}
}
void loop()
{
// update the menuIndex value
menuIndex = boundedValueCalculator(menuIndex, 0, 3, 0);
switch (menuIndex)
{
case 0:
MenuRxTxInfos();
break;
case 1:
MenuConnectionStatus();
break;
case 2:
MenuSequence();
break;
}
}