#include "lib7seg.h"
unsigned int datain[4] = {};
unsigned char E_actif = 0;
void setup() {
Serial.begin(115200);
Serial.println("debut");
pinMode(A0, INPUT);
pinMode(A1, INPUT);
pinMode(A2, INPUT);
pinMode(A4, INPUT);
setup7seg();
setupTimer2();
}
void setupTimer2(){
cli(); // disable all interrupts
TCCR2A = (1<<WGM21)|(0<<WGM20); // Mode CTC
TIMSK2 = (1<<OCIE2A); // Local interruption OCIE2A
TCCR2B = (0<<WGM22)|(1<<CS22)|(1<<CS21); // prediviser /256
OCR2A = 250; //250*256*1/16000000 = 4ms
sei(); // enable all interrupts
}
//appelée toutes les 4ms:
ISR(TIMER2_COMPA_vect){ // timer compare interrupt service routine
refresh();
}
void tache1(){
datain[0]=analogRead(A0);
datain[1]=analogRead(A1);
datain[2]=analogRead(A2);
datain[3]=analogRead(A4);
for (int i=0;i<4;i++){
Serial.print(datain[i]);
Serial.print(" ");
}
Serial.println();
}
void tache2(){
E_actif++;
if(E_actif > 3){
E_actif = 0;
}
}
void tache3(){
static int dot =0;
dot = 1<<E_actif;
setNumber(datain[E_actif]);
Setdot(dot);
}
///////////////////////////
///////////////////////////
void loop() {
tache3();
unsigned int periodiciteTache1=100; //100ms entre chaque incrémentation de la valeur à afficher
unsigned int periodiciteTache2=2000; //2s
static unsigned long timerTache1 = millis();
static unsigned long timerTache2 = millis();
if (millis() - timerTache1 >= periodiciteTache1) {
timerTache1 += periodiciteTache1;
tache1();
}
if (millis() - timerTache2 >= periodiciteTache2) {
timerTache2 += periodiciteTache2;
tache2();
}
}
///////////////////////////