
TP2_exo3
Revision 0:ab9cb51da05c, committed 2014-10-23
- Comitter:
- mbedo
- Date:
- Thu Oct 23 12:13:51 2014 +0000
- Commit message:
- TP2_exo3
Changed in this revision
Exo3.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r ab9cb51da05c Exo3.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Exo3.cpp Thu Oct 23 12:13:51 2014 +0000 @@ -0,0 +1,43 @@ +#include "mbed.h" + +InterruptIn button(p15); // on initialise nos bouton à l'entrée +InterruptIn button2(p16); +InterruptIn button3(p17); +DigitalOut led[] = {LED1,LED2,LED3,LED4}; // On crée un tableau avec comme indice nos LEDs + + +int i=0; +void fonction_plus(void) // on crée la fonction qui nous permettera d'incrémenter la valeur de i +{ + if (i>3) { // on ramène la valeur de i à 3 si elle est supérieure pour ne pas "buguer" le système + i=3; + } + + led[i]=1; // On va chercher dans le tableau la LED à allumer en fonction de l'indice de i + i++; // on incrémente i +} + +void fonction_moins(void) +{ + if (i<=0) { // A l'inverse on se charge que i soit strictement supérieur à 0 pour les mêmes raisons qu'au dessus + i=1; + } + + i--; // le retrait de 1 à i doit se faire avant l'exctinction d'une LED sinon il y a un appui inutile + led[i]=0; +} +void fonction_reset(void) +{ + for(i=0; i<4; i++) { // On crée une boucle for qui permet de parcourir tous les indices du tableau et donc d'éteindre toutes les LEDs + led[i]=0; + } + i=0; +} +int main() +{ + button.fall(fonction_plus); // l'interruption agit sur front descendant donc dès que le bouton 1 est enclenché la fonction_plus s'active de même pour le bouton2 et 3. + button3.fall(fonction_reset); + button2.fall(fonction_moins); + while(1); +} +
diff -r 000000000000 -r ab9cb51da05c mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu Oct 23 12:13:51 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/552587b429a1 \ No newline at end of file