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.
main.cpp@2:413bb11fe2e7, 2021-02-19 (annotated)
- Committer:
- fdurand
- Date:
- Fri Feb 19 08:04:37 2021 +0000
- Revision:
- 2:413bb11fe2e7
- Parent:
- 1:4d5a771fa495
exercice;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
pierreprovent | 0:57304dca9808 | 1 | #include "mbed.h" |
pierreprovent | 0:57304dca9808 | 2 | |
pierreprovent | 1:4d5a771fa495 | 3 | Serial pc(USBTX, USBRX); |
fdurand | 2:413bb11fe2e7 | 4 | Ticker monticker; |
pierreprovent | 0:57304dca9808 | 5 | |
pierreprovent | 1:4d5a771fa495 | 6 | AnalogIn Ve(PA_3); // CAN sur A0 connecteur Arduino |
fdurand | 2:413bb11fe2e7 | 7 | |
fdurand | 2:413bb11fe2e7 | 8 | // Variable globales |
fdurand | 2:413bb11fe2e7 | 9 | |
fdurand | 2:413bb11fe2e7 | 10 | int drapeau; |
fdurand | 2:413bb11fe2e7 | 11 | float voltage; |
fdurand | 2:413bb11fe2e7 | 12 | int temp=0; |
fdurand | 2:413bb11fe2e7 | 13 | char buff[3]; // tableau de char pour réaliser un buffer de 3 caractéres |
fdurand | 2:413bb11fe2e7 | 14 | char buff2[3]; // tableau de char pour réaliser un buffer de 3 caractères |
fdurand | 2:413bb11fe2e7 | 15 | // programme permetant de lire une valeure du signal |
fdurand | 2:413bb11fe2e7 | 16 | void lire() { |
fdurand | 2:413bb11fe2e7 | 17 | float val = Ve.read(); |
fdurand | 2:413bb11fe2e7 | 18 | voltage=3.3*val; // en V |
fdurand | 2:413bb11fe2e7 | 19 | temp=voltage*50; |
fdurand | 2:413bb11fe2e7 | 20 | drapeau=1; |
fdurand | 2:413bb11fe2e7 | 21 | } |
pierreprovent | 0:57304dca9808 | 22 | |
pierreprovent | 1:4d5a771fa495 | 23 | int main() |
pierreprovent | 0:57304dca9808 | 24 | { |
fdurand | 2:413bb11fe2e7 | 25 | monticker.attach(&lire,1); |
fdurand | 2:413bb11fe2e7 | 26 | //pc.printf("Test du convertisseur analogique numérique\n"); |
fdurand | 2:413bb11fe2e7 | 27 | //pc.printf("Relier la sortie de votre préamplificateur a A0 (CAN) du connecteur Arduino\n"); |
fdurand | 2:413bb11fe2e7 | 28 | |
fdurand | 2:413bb11fe2e7 | 29 | while (1) { |
fdurand | 2:413bb11fe2e7 | 30 | wait_ms (100); |
fdurand | 2:413bb11fe2e7 | 31 | |
fdurand | 2:413bb11fe2e7 | 32 | if (drapeau==1) { |
fdurand | 2:413bb11fe2e7 | 33 | //pc.printf("%2d",temp); |
fdurand | 2:413bb11fe2e7 | 34 | sprintf(buff, "%.2f",voltage); |
fdurand | 2:413bb11fe2e7 | 35 | pc.printf(buff); |
fdurand | 2:413bb11fe2e7 | 36 | |
fdurand | 2:413bb11fe2e7 | 37 | sprintf(buff2, "%3d",temp); |
fdurand | 2:413bb11fe2e7 | 38 | pc.printf(buff2); |
fdurand | 2:413bb11fe2e7 | 39 | |
fdurand | 2:413bb11fe2e7 | 40 | drapeau=0; |
fdurand | 2:413bb11fe2e7 | 41 | } |
pierreprovent | 1:4d5a771fa495 | 42 | } |
pierreprovent | 0:57304dca9808 | 43 | } |