Guillaume Alli / Mbed 2 deprecated TP7_IUT_NICE

Dependencies:   mbed info1 TSI

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Exo1.cpp Source File

Exo1.cpp

00001 #define Exo1
00002 #ifdef  Exo1
00003 
00004 #include "mbed.h"
00005 #include "info1.h"
00006 
00007 #define LOW 0
00008 #define HIGH 1
00009 
00010 //pour le debug (printf & scanf)
00011 Serial pc(USBTX, USBRX); 
00012 
00013 int main(void)
00014 {
00015     //Declaration des variables :
00016     int etat;
00017     int bp;
00018     PwmOut led(LED_BLUE);
00019 
00020     //Initialisation
00021     etat=0;
00022     led.period_us(100);
00023 
00024     //Boucle infinie
00025     while (1) {
00026         //Lecture du slider (bp=1 si doigt sur slider, 0 sinon)  
00027         appui_num(&bp);
00028 
00029         //Determination de l'etat en fonction de BP
00030         switch(etat) 
00031         {
00032             case 0:
00033                 if (bp==HIGH) 
00034                 {
00035                     etat =1; 
00036                 }
00037                 break;
00038             case 1:
00039                 if (bp==LOW)   
00040                 {
00041                     etat =2; 
00042                 }
00043                 break;
00044             case 2:
00045                 if (bp==HIGH)
00046                 {  
00047                     etat =3; 
00048                 }
00049                 break;
00050             case 3:
00051                 if (bp==LOW) 
00052                 {  
00053                     etat =0; 
00054                 }
00055                 break;
00056         }
00057 
00058         //Ecriture sur les sorties en fct de l'etat
00059         switch(etat) 
00060         {
00061             case 0:
00062                 led=1; 
00063                 break;
00064             case 1:
00065                 led=1; 
00066                 break;
00067             case 2:
00068                 led=0; 
00069                 break;
00070             case 3:
00071                 led=0; 
00072                 break;
00073         }
00074 
00075         wait_ms(10);
00076     }
00077 }
00078 #endif