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
Fork of APP1_customProtocole by
main.cpp@5:259661cbf9c3, 2016-01-11 (annotated)
- Committer:
- yannolecool
- Date:
- Mon Jan 11 04:04:54 2016 +0000
- Revision:
- 5:259661cbf9c3
- Parent:
- 4:e6df056992c1
- Child:
- 6:5c8e02d5ebcc
Ajout de l'interface custom pour le UART
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| yannolecool | 0:544fa864099a | 1 | #include "mbed.h" |
| yannolecool | 3:b3574c385012 | 2 | #include "acceleroMMA8452Q.h" |
| yannolecool | 5:259661cbf9c3 | 3 | #include "customUART.h" |
| yannolecool | 2:451888674389 | 4 | |
| yannolecool | 2:451888674389 | 5 | Serial pc(USBTX, USBRX); |
| yannolecool | 5:259661cbf9c3 | 6 | CustomUART afficheur; |
| yannolecool | 1:7b43594a95f3 | 7 | |
| yannolecool | 1:7b43594a95f3 | 8 | void display2decimal(int number); |
| yannolecool | 2:451888674389 | 9 | |
| yannolecool | 0:544fa864099a | 10 | |
| yannolecool | 0:544fa864099a | 11 | int main() { |
| yannolecool | 2:451888674389 | 12 | |
| yannolecool | 3:b3574c385012 | 13 | Accelero accelero(100000); |
| yannolecool | 2:451888674389 | 14 | |
| yannolecool | 0:544fa864099a | 15 | while(1) { |
| yannolecool | 3:b3574c385012 | 16 | vector acceleroVector = accelero.getAccelVector(); |
| yannolecool | 3:b3574c385012 | 17 | |
| yannolecool | 3:b3574c385012 | 18 | pc.printf("X: %i \n\r", acceleroVector.x); |
| yannolecool | 3:b3574c385012 | 19 | pc.printf("Y: %i \n\r", acceleroVector.y); |
| yannolecool | 3:b3574c385012 | 20 | pc.printf("Z: %i \n\n\r", acceleroVector.z); |
| yannolecool | 3:b3574c385012 | 21 | |
| yannolecool | 3:b3574c385012 | 22 | display2decimal(accelero.getAngle()); |
| yannolecool | 1:7b43594a95f3 | 23 | wait(0.5); |
| yannolecool | 0:544fa864099a | 24 | } |
| yannolecool | 0:544fa864099a | 25 | } |
| yannolecool | 1:7b43594a95f3 | 26 | |
| yannolecool | 1:7b43594a95f3 | 27 | //Affiche automatique un nombre avec 2 dgits |
| yannolecool | 1:7b43594a95f3 | 28 | //Pour display 12.35 il faut envoyer 1235 |
| yannolecool | 1:7b43594a95f3 | 29 | void display2decimal(int number) |
| yannolecool | 1:7b43594a95f3 | 30 | { |
| yannolecool | 1:7b43594a95f3 | 31 | int digit1 = number / 1000; |
| yannolecool | 1:7b43594a95f3 | 32 | int rest = number - digit1 * 1000; |
| yannolecool | 1:7b43594a95f3 | 33 | int digit2 = rest / 100; |
| yannolecool | 1:7b43594a95f3 | 34 | rest -= digit2 * 100; |
| yannolecool | 1:7b43594a95f3 | 35 | int digit3 = rest / 10; |
| yannolecool | 1:7b43594a95f3 | 36 | rest -= digit3 * 10; |
| yannolecool | 1:7b43594a95f3 | 37 | int digit4 = rest; |
| yannolecool | 1:7b43594a95f3 | 38 | |
| yannolecool | 1:7b43594a95f3 | 39 | //Put the cursor at the first digit |
| yannolecool | 1:7b43594a95f3 | 40 | afficheur.putc(0x79); |
| yannolecool | 1:7b43594a95f3 | 41 | afficheur.putc(0x00); |
| yannolecool | 1:7b43594a95f3 | 42 | |
| yannolecool | 1:7b43594a95f3 | 43 | //Write 2 first digits |
| yannolecool | 1:7b43594a95f3 | 44 | afficheur.putc(digit1); |
| yannolecool | 1:7b43594a95f3 | 45 | afficheur.putc(digit2); |
| yannolecool | 1:7b43594a95f3 | 46 | |
| yannolecool | 1:7b43594a95f3 | 47 | //Add the dot after two digit |
| yannolecool | 1:7b43594a95f3 | 48 | afficheur.putc(0x77); |
| yannolecool | 1:7b43594a95f3 | 49 | afficheur.putc(0b00000010); |
| yannolecool | 1:7b43594a95f3 | 50 | |
| yannolecool | 1:7b43594a95f3 | 51 | //Write the last two digits |
| yannolecool | 1:7b43594a95f3 | 52 | afficheur.putc(digit3); |
| yannolecool | 1:7b43594a95f3 | 53 | afficheur.putc(digit4); |
| yannolecool | 1:7b43594a95f3 | 54 | } |
