Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 5:0d73e455922a, committed 2020-05-04
- Comitter:
- jdeschamps
- Date:
- Mon May 04 14:40:43 2020 +0000
- Parent:
- 4:2054aa78f3fd
- Commit message:
- projetv1
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Mon May 04 13:37:55 2020 +0000 +++ b/main.cpp Mon May 04 14:40:43 2020 +0000 @@ -1,5 +1,5 @@ #include "mbed.h" - +#include "string.h" Serial pc(USBTX, USBRX,9600); // tx, rx sur les broches associées au bus USB DigitalOut led1(LED1); DigitalOut brka (PTC4); @@ -7,14 +7,31 @@ DigitalOut dira (PTD3); DigitalOut dirb (PTD1); DigitalOut pwma (PTD2); +InterruptIn sw3 (PTA4); +InterruptIn sw2 (PTC6); char pas=1; bool sens=0; bool F; unsigned int compteur=0; char message[30]; +int err; +int i=0; +int o=0; Ticker mon_IT; // on associe l'interface Timeout à l'objet mon_IT +void Interruption_KBI1() { + i++; + printf("La valeur de i est de : %d \n", i); + pwma=0; + } + +void Interruption_KBI2() { + o++; + printf("La valeur de o est de : %d \n", o); + pwma=0; + printf("Le nombre de pas est de : %d \n", compteur); + void Interruption_timer() { if(sens==0) { @@ -29,7 +46,7 @@ if(pas<1)pas=8; } if(compteur<=0){ - PWMA_ClrVal(); + pwma=0; F=1; } switch (pas) @@ -91,33 +108,39 @@ { mon_IT.attach(&Interruption_timer,0.5); // l'interruption est associée au programme Interruption_timer et s'exécute toutes les 0.5s // pour stopper mon_IT.detach(); + sw3.rise(&Interruption_KBI1); + sw3.rise(&Interruption_KBI2); while(1) { for(;;){ - if (F==1) - { - - Term1_SendStr("Fin de course"); - Term1_CRLF(); - F=0; - } - if (Term1_KeyPressed()==1) - { - Term1_ReadLine(message); - if(strcmp(message,"monte_v1")==0) + + if (pc.readable()){ + err=pc.scanf("%s",message); + + if(strcmp(message,"monte_v1")==0) { sens=0; // marche avant pwma=1; - TI1_EnableEvent(); } + else if(strcmp(message,"descend_v1")==0) { sens=1; // marche arriere pwma=1; - TI1_EnableEvent(); - } - } + } + + else if(strcmp(message,"stop")==0) + { + pwma=0; + + } + + if (F==1) + { + printf("Fin de course"); + F=0; + } } } - - +} +}