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.
exemple_simple.cpp@5:1c558b1e6236, 2015-01-15 (annotated)
- Committer:
- Agachon
- Date:
- Thu Jan 15 10:29:22 2015 +0000
- Revision:
- 5:1c558b1e6236
- Parent:
- 2:f1f3e7bc7ef6
- Child:
- 6:69101b9b0c17
V3
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Agachon | 5:1c558b1e6236 | 1 | #define exemple_simple |
| Agachon | 1:163ab968a125 | 2 | #ifdef exemple_simple |
| Agachon | 1:163ab968a125 | 3 | |
| Agachon | 1:163ab968a125 | 4 | #include "mbed.h" |
| Agachon | 1:163ab968a125 | 5 | |
| Agachon | 1:163ab968a125 | 6 | int main(void) |
| Agachon | 1:163ab968a125 | 7 | { |
| Agachon | 1:163ab968a125 | 8 | //creation d'une variable led de type PWM (modulation de largeur d'impulsion) |
| Agachon | 1:163ab968a125 | 9 | //la variable led est connectée a la led rouge du mbed |
| Agachon | 1:163ab968a125 | 10 | //On peut choisir la couleur de la led (LED_RED pour la rouge, LED_GREEN pour la verte |
| Agachon | 1:163ab968a125 | 11 | //et LED_BLUE pour la bleue |
| Agachon | 1:163ab968a125 | 12 | PwmOut led(LED_RED); |
| Agachon | 1:163ab968a125 | 13 | |
| Agachon | 1:163ab968a125 | 14 | //Initialisation de la periode de rafraichissement de la PWM |
| Agachon | 1:163ab968a125 | 15 | led.period_us(100); |
| Agachon | 1:163ab968a125 | 16 | |
| Agachon | 1:163ab968a125 | 17 | //Boucle infinie |
| Agachon | 1:163ab968a125 | 18 | while(1) { |
| Agachon | 1:163ab968a125 | 19 | // eteint la led! L'argument entre parenthese correspond au pourcentage du temps a |
| Agachon | 1:163ab968a125 | 20 | // bas de la sortie PWM. Dans le cas ci dessous, la valeur moyenne de la sortie PWM |
| Agachon | 1:163ab968a125 | 21 | // est egale a 0v (donc led eteinte); |
| Agachon | 1:163ab968a125 | 22 | led = 1; |
| Agachon | 1:163ab968a125 | 23 | // Endort le systeme pendant 200ms |
| Agachon | 1:163ab968a125 | 24 | wait_ms(200); |
| Agachon | 1:163ab968a125 | 25 | // Allume la led. Le temps à l'etat bas etant egal a 0% de la periode, la |
| Agachon | 1:163ab968a125 | 26 | //valeur moyenne de la sortie PWM est egale a 5v (donc led allumee). |
| Agachon | 1:163ab968a125 | 27 | led = 0; |
| Agachon | 1:163ab968a125 | 28 | // Endort le systeme pendant 200ms |
| Agachon | 1:163ab968a125 | 29 | wait_ms(800); |
| Agachon | 1:163ab968a125 | 30 | } |
| Agachon | 1:163ab968a125 | 31 | } |
| Agachon | 1:163ab968a125 | 32 | |
| Agachon | 1:163ab968a125 | 33 | #endif |