#include "lib7seg.h"*
#include "class.h"
int temps=0;
CStateMachineRotary encodeur(A4,A5);
void setup() {
Serial.begin(115200);
Serial.println("debut");
setup7seg();
setupTimer2();
pinMode(A3,OUTPUT);
analogWrite(A3,LOW);
pinMode(A0, OUTPUT);
pinMode(A1, OUTPUT);
pinMode(A2, OUTPUT);
pinMode(A4, INPUT);
pinMode(A5, OUTPUT);
}
///////////////////////////
void tache1() {
cli(); // disable all interrupts
temps ++;
setNumber(temps);
sei(); // enable all interrupts
delay(25);
}
///////////////////////////
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 = 2000; //4ms pour l'affichage de chaque digit
static unsigned long timerTache1 = millis();
static unsigned long timerTache2 = millis();
if (millis() - timerTache1 >= periodiciteTache1) {
timerTache1 += periodiciteTache1;
//applicationTache1();
}
if (millis() - timerTache2 >= periodiciteTache2) {
timerTache2 += periodiciteTache2;
applicationTache2();
}
//applicationTache3();
Serial.println(encodeur.getPosition());
}
///////////////////////////