#include <Wire.h>
#include "interruptions.h"
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd1(0x20, 16, 2); // set the LCD address to 0x20 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd2(0x21, 16, 2); // set the LCD address to 0x20 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd3(0x27, 16, 2); // set the LCD address to 0x20 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd4(0x23, 16, 2); // set the LCD address to 0x20 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd5(0x24, 16, 2); // set the LCD address to 0x20 for a 16 chars and 2 line displaybyte switch[]={ 0,22,23,24,25};
const byte BP = 5; // this is the Arduino pin we are connecting the push button to
const byte switchs []={ 0,22,24,26,28,30,32,34,36};
const byte led [] ={ 0,23,25,27,29,31,33,35,37};
bool stateswitch[] ={ false,false,false,false,false};
bool laststateswitch[]={ false,false,false,false,false};
bool layer[] ={ false, true,false,false,false};//layer1 sélectionné par défaut
unsigned long tempo_anti_rebonds_BP = 20; // tempo de prise en compte de rebonds
unsigned long BP_long = 1000; // appui > 2 secondes sur BP Reset c'est un appui long
unsigned long chrono_appui_BP = millis(); // chrono pour appui long ou court sur BP_reset
unsigned long chrono_BP_relache = millis(); // chrono pour anti rebonds au relachement
bool appui_BP_valide = false;
bool appui_long = false;
bool appui_court = false;
bool appui_BP = false;
const byte switch_encodeur[]={3,4,5,6,7,8,9,10,11};
unsigned long chrono_appui_switch[ ]={millis(),millis(),millis(),millis(),millis(),millis(),millis(),millis(),millis()};
unsigned long chrono_switch_relache[]={millis(),millis(),millis(),millis(),millis(),millis(),millis(),millis(),millis()};
unsigned long tempo_anti_rebonds_switch=100;
bool switch_appuye[] ={ false,false,false,false,false,false,false,false,false};
bool switch_relache[]={ false,false,false,false,false,false,false,false,false};
//byte Mode = 0; // This is which menu mode we are in at any given time (top level or one of the submenus)
//int modeMax = 3; // This is the number of submenus/settings you want
uint16_t memo_encodeur_1 = 0;//A8 A9
uint16_t memo_encodeur_2 = 0;//A10 A11
uint16_t memo_encodeur_3 = 0;//A12 A13
uint16_t memo_encodeur_4 = 0;//A14 A15
uint16_t memo_encodeur_5 = 0;//53 52
uint16_t memo_encodeur_6 = 0;//51 50
uint16_t memo_encodeur_7 = 0;//10 11
uint16_t memo_encodeur_8 = 0;//12 13
void setup()
{
Serial.begin (115200);
for (byte f=1;f<=4;f++){pinMode (switchs[f], INPUT_PULLUP);}
for (byte f=1;f<=4;f++){digitalWrite(led[f],LOW);pinMode (led[f], OUTPUT);}
pinMode (BP, INPUT_PULLUP); // setup the button pin
//pinMode(PinA, INPUT_PULLUP); // set pinA as an input, pulled HIGH to the logic voltage (5V or 3.3V for most cases)
//pinMode(PinB, INPUT_PULLUP); // set pinB as an input, pulled HIGH to the logic voltage (5V or 3.3V for most cases)
//attachInterrupt(0,pinA,RISING);
//attachInterrupt(1,pinB,RISING);
lcd1.init();lcd1.backlight();
lcd2.init();lcd2.backlight();
lcd3.init();lcd3.backlight();
lcd4.init();lcd4.backlight();
lcd5.init();lcd5.backlight();
digitalWrite (led[1], HIGH);
Serial.print ("layer1 = ");
Serial.print (layer[1]);
init_interruptions();
}
void loop()
{
timer();
lecture_switchs(); //et selection d'un niveau
affichage();//lecture_encodeur(); //et switch
gestion_leds();
gestion_lcd();
}
void init_interruptions()
{
DDRK = 0b00000000; // portK en entrée
PORTK = 0b11111111; // pullup portK activées
DDRB = 0b00000000; // portB en entrée
PORTB = 0b11111111; // pullup portB activées
PCICR |= (1 << PCIE2)|(1 << PCIE0); // validation du groupe 0 (portB) en interruptible 53,52,51,50,10,11,12,13
//PCICR |= (1 << PCIE0); // validation du groupe 2 (portK) en interruptible A8,A9,A10,A11,A12,A13,A14,A15
PCMSK2 = 0b11111111; // sélection des entrées interruptibles dans le groupe 2(portK)
PCMSK0 = 0b11111111; // sélection des entrées interruptibles dans le groupe 0(portB)
sei(); // autorisation des interruptions
}