Académique Documents
Professionnel Documents
Culture Documents
Sommaire
1 Objectifs
2 Initialisation: Durée & temps de départ
3 Lecture de l’ordonnanceur
4 Initialisation de l’ordonnanceur avec la période de répétition
5 Génération des conditions de début des taches
6 Génération des conditions d’arrêts
7 Exécution des tâches
8 Exemple de 3 tâches
9 Sujets connexes
Objectifs
1. Savoir ordonnancer les taches avec Arduino
2. Savoir définir les conditions de départs et arrêts des taches
3. Savoir initialiser l’ordonnanceur
4. Etc.
Tache_duree[0]=5000;
Tache_duree[1]=5000;
Tache_duree[2]=5000;
Tache_start[0]=10000;
Tache_start[1]=20000;
Tache_start[2]=30000;
Serial.begin(9600);
pinMode(PinLED1,OUTPUT);
pinMode(PinLED2,OUTPUT);
pinMode(PinLED3,OUTPUT);
Lecture de l’ordonnanceur
Master_time=millis();
Tache_on[i]=(Master_time>Tache_start[i]);
Tache_off[i]=Tache_on[i]& (Master_time<(Tache_start[i]+Tache_duree[i]));
if(Tache_off[0])
analogWrite(PinLED1,255);
analogWrite(PinLED2,0);
analogWrite(PinLED3,0);
Tache_Active=1;
// Tâche 2
else if(Tache_off[1])
analogWrite(PinLED1,0);
analogWrite(PinLED2,255);
analogWrite(PinLED3,0);
Tache_Active=2;
// Tâche 3
else if(Tache_off[2])
analogWrite(PinLED1,0);
analogWrite(PinLED2,0);
analogWrite(PinLED3,255);
Tache_Active=3;
else
analogWrite(PinLED1,0);
analogWrite(PinLED2,0);
analogWrite(PinLED3,0);
Tache_Active=0;
Serial.print(Master_time/1000);
Serial.print(":");
Serial.println(Master_time%1000);
Exemple de 3 tâches
#define NumTache 3
#define DureeRep_ms 40000
#define PinLED1 2
#define PinLED2 3
#define PinLED3 4
unsigned char Tache_on[NumTache],Tache_off[NumTache];
void setup()
{
// Init écheances des taches (en ms)
Tache_duree[0]=5000;
Tache_duree[1]=5000;
Tache_duree[2]=5000;
void loop()
{
// Lecture de l'ordonnanceur
Master_time=millis();
// Tâche 1
if(Tache_off[0])
{
analogWrite(PinLED1,255);
analogWrite(PinLED2,0);
analogWrite(PinLED3,0);
Tache_Active=1;
}
// Tâche 2
else if(Tache_off[1])
{
analogWrite(PinLED1,0);
analogWrite(PinLED2,255);
analogWrite(PinLED3,0);
Tache_Active=2;
}
// Tâche 3
else if(Tache_off[2])
{
analogWrite(PinLED1,0);
analogWrite(PinLED2,0);
analogWrite(PinLED3,255);
Tache_Active=3;
}
// Autres: Désactivation des sorties
else
{
analogWrite(PinLED1,0);
analogWrite(PinLED2,0);
analogWrite(PinLED3,0);
Tache_Active=0;
}
// Affichage de la tache active
Serial.print(Master_time/1000);
Serial.print(":");
Serial.println(Master_time%1000);
}
Sujets connexes
arduino boucles simultanées
arduino actions simultanées
plusieurs loop arduino
arduino plusieurs capteurs
arduino temporisation non bloquante
arduino multitâche avec timer
arduino astuces
programme arduino complexe
arduino multitâche
machine d’état arduino