#include "lib7seg.h"
void setup() {
setup7seg();
setupTimer2();
}
//Timer 2 : https://www.aranacorp.com/fr/utilisation-des-timers-de-larduino/
// timer2 (8 bits) qui est utilisé par la fonction Tone() et la génération de la PWM sur les broches 3 et 11.
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 loop()
{
unsigned int periodiciteTache1=100; //100ms entre chaque incrémentation de la valeur à afficher
unsigned int periodiciteTache2=4; //4ms pour l'affichage de chaque digit
static unsigned long timerTache1 = millis();
static unsigned long timerTache2 = millis();
if (millis() - timerTache1 >= periodiciteTache1) {
timerTache1 += periodiciteTache1;
tache1();
}
if (millis() - timerTache2 >= periodiciteTache2) {
timerTache2 += periodiciteTache2;
refresh();
}
}
//setDigit(2,tabDeco7seg[15]);
/// END ///