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.
Dependencies: mbed
Revision 1:3624dcc1851d, committed 2020-08-31
- Comitter:
- snec_student
- Date:
- Mon Aug 31 13:05:20 2020 +0000
- Parent:
- 0:82242c25009e
- Commit message:
- version finale liaison serie;
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Thu Aug 27 20:25:43 2020 +0000
+++ b/main.cpp Mon Aug 31 13:05:20 2020 +0000
@@ -1,29 +1,24 @@
#include "mbed.h"
DigitalOut Led_rouge(PTB22);
Ticker horloge; // creation de l'objet "horloge" de type "Ticker"
-InterruptIn KBI_SW2(SW2); // création de l'objet KBI_SW2 associé à l'interruption
-InterruptIn KBI_SW3(SW3); // création de l'objet KBI_SW3 associé à l'interruption
+Serial pc(USBTX,USBRX); // on instancie une liaison série appelée pc à 9600 bauds sur la liaison usb
void IT_horloge() // écriture du sous programme d'interruption associé au Ticker
{
Led_rouge=!Led_rouge; // la led rouge change d'état
}
-void IT_SW2() // ecriture du sous programme appui SW2
-{
-horloge.attach(&IT_horloge,0.1); // on lance le IT lors d'un appui sur SW2
-}
-void IT_SW3() // ecriture du sous programme appui SW3
-{
-horloge.detach(); // on arrete les IT lors d'un appui sur SW3
-Led_rouge=1; // on éteint la led rouge
-}
int main ()
{
- Led_rouge=1; // on éteint la led rouge
- KBI_SW2.fall(&IT_SW2); // le programme IT_SW2 est attaché a l'appui sur SW2
- KBI_SW3.fall(&IT_SW3); // le programme IT_SW3 est attaché a l'appui sur SW3
+char chaine[5]; // memoire de reception des messages
+Led_rouge=1; // on éteint la led rouge
while(1)
{
+ if (pc.readable())
+ {
+ pc.scanf("%5s",chaine); // on recopie dans chaine le message reçu limité à ( caractères
+ if (strcmp(chaine,"ON")==0) horloge.attach(&IT_horloge,0.1); // on allume la led si l'on a reçu ON
+ else if (strcmp(chaine,"OFF")==0) horloge.detach(); // on éteint la led si l'on a reçu OFF
+ }
}
}
\ No newline at end of file