1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
| #include <stdio.h>
#include <stdlib.h>
//** constantes utilisées **//
#define VERS_DROITE 1
#define VERS_GAUCHE 2
#define BOUTON_ACTIF 1
#define BOUTON_INACTIF 2
#define NB_LED 8
//** prototypes des fonctions utilisées **//
//renvoi l'etat du bouton
unsigned int LireEtatBouton();
//allume la led dont le numéro est passé en paramétre
void AllumeLed(unsigned int);
int main(void){
unsigned int etat_bp =BOUTON_INACTIF;
unsigned int pos_chenillard = 1; //premier LED
unsigned int sens_chenillard =VERS_DROITE;
//boucle principal
while(1) {
//lecture du bouton poussoir
etat_bp=LireEtatBouton();
//si le bouton est actif on affiche le chennillard sinon ne rien faire
if(etat_bp==BOUTON_ACTIF) {
//on regarde dans quel sens on doit aller
switch(sens_chenillard) {
case VERS_DROITE :
pos_chenillard++;
if(pos_chenillard >NB_LED) {
sens_chenillard=VERS_GAUCHE;
pos_chenillard--;
}
break;
case VERS_GAUCHE :
pos_chenillard--;
if(pos_chenillard <1) {
sens_chenillard=VERS_DROITE;
pos_chenillard++;
}
break;
}
//on allume la led
AllumeLed(pos_chenillard);
}
//ajouter une temporisation
}
return 0;
}
void AllumeLed(unsigned int led) {
//eteindre toutes les leds et
//allumer la led dont le numéro est passé en paramètre
}
unsigned int LireEtatBouton() {
unsigned int etat_bp;
//lire le registre qui va bien avec la fonction qui va bien et stocker
//le resultat dans etat_bp
return etat_bp;
} |