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.
Fork of 01-04EntregaPrimerCorte by
main.cpp@2:dc3183a4bdf4, 2018-09-30 (annotated)
- Committer:
- danielgarciag
- Date:
- Sun Sep 30 21:17:00 2018 +0000
- Revision:
- 2:dc3183a4bdf4
- Parent:
- 1:526bdd5faa37
proyecto ara?a
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| fabeltranm | 0:89b318e49395 | 1 | #include "mbed.h" |
| fabeltranm | 0:89b318e49395 | 2 | |
| fabeltranm | 0:89b318e49395 | 3 | #include "main.h" |
| fabeltranm | 0:89b318e49395 | 4 | |
| fabeltranm | 0:89b318e49395 | 5 | |
| fabeltranm | 0:89b318e49395 | 6 | |
| fabeltranm | 0:89b318e49395 | 7 | |
| fabeltranm | 0:89b318e49395 | 8 | Serial command(USBTX, USBRX); |
| fabeltranm | 0:89b318e49395 | 9 | |
| fabeltranm | 0:89b318e49395 | 10 | |
| fabeltranm | 0:89b318e49395 | 11 | |
| fabeltranm | 0:89b318e49395 | 12 | int main() { |
| fabeltranm | 0:89b318e49395 | 13 | init_servo(); |
| fabeltranm | 0:89b318e49395 | 14 | init_serial(); |
| fabeltranm | 1:526bdd5faa37 | 15 | |
| fabeltranm | 0:89b318e49395 | 16 | debug_m("inicio \n"); |
| fabeltranm | 0:89b318e49395 | 17 | uint32_t read_cc; |
| fabeltranm | 0:89b318e49395 | 18 | while(1) |
| fabeltranm | 0:89b318e49395 | 19 | { |
| fabeltranm | 0:89b318e49395 | 20 | read_cc=read_command(); |
| fabeltranm | 0:89b318e49395 | 21 | switch (read_cc) { |
| fabeltranm | 1:526bdd5faa37 | 22 | case 0x01: moving(); break; |
| fabeltranm | 0:89b318e49395 | 23 | default: debug_m("error de comando. \nSe espera 0xFEF0 o 0xFFF0 \n");break ; |
| fabeltranm | 0:89b318e49395 | 24 | } |
| fabeltranm | 0:89b318e49395 | 25 | } |
| fabeltranm | 0:89b318e49395 | 26 | } |
| fabeltranm | 0:89b318e49395 | 27 | |
| fabeltranm | 0:89b318e49395 | 28 | |
| fabeltranm | 0:89b318e49395 | 29 | |
| fabeltranm | 0:89b318e49395 | 30 | uint32_t read_command() |
| fabeltranm | 0:89b318e49395 | 31 | { |
| fabeltranm | 1:526bdd5faa37 | 32 | // retorna los byte recibidos concatenados en un entero, |
| fabeltranm | 0:89b318e49395 | 33 | |
| fabeltranm | 1:526bdd5faa37 | 34 | |
| fabeltranm | 1:526bdd5faa37 | 35 | |
| fabeltranm | 1:526bdd5faa37 | 36 | char intc=command.getc(); |
| fabeltranm | 0:89b318e49395 | 37 | |
| danielgarciag | 2:dc3183a4bdf4 | 38 | while(intc != 0xff) |
| fabeltranm | 1:526bdd5faa37 | 39 | intc=command.getc(); |
| danielgarciag | 2:dc3183a4bdf4 | 40 | return command.getc(); |
| fabeltranm | 0:89b318e49395 | 41 | } |
| fabeltranm | 1:526bdd5faa37 | 42 | |
| fabeltranm | 1:526bdd5faa37 | 43 | |
| fabeltranm | 0:89b318e49395 | 44 | void init_serial() |
| fabeltranm | 0:89b318e49395 | 45 | { |
| fabeltranm | 0:89b318e49395 | 46 | command.baud(9600); |
| fabeltranm | 0:89b318e49395 | 47 | } |
| fabeltranm | 0:89b318e49395 | 48 | |
| fabeltranm | 0:89b318e49395 | 49 | |
| fabeltranm | 1:526bdd5faa37 | 50 | void moving(){ |
| fabeltranm | 1:526bdd5faa37 | 51 | debug_m("se inicia el comado mover..\n"); |
| fabeltranm | 0:89b318e49395 | 52 | |
| fabeltranm | 1:526bdd5faa37 | 53 | char nmotor=command.getc(); |
| fabeltranm | 1:526bdd5faa37 | 54 | char grados=command.getc(); |
| fabeltranm | 1:526bdd5faa37 | 55 | char endc=command.getc(); |
| danielgarciag | 2:dc3183a4bdf4 | 56 | debug_m("MOTOR: %d grados : %d \n", nmotor, grados); |
| danielgarciag | 2:dc3183a4bdf4 | 57 | |
| danielgarciag | 2:dc3183a4bdf4 | 58 | mover_ser(nmotor,grados); |
| danielgarciag | 2:dc3183a4bdf4 | 59 | debug_m("fin del comado mover..\n"); |
| fabeltranm | 0:89b318e49395 | 60 | |
| fabeltranm | 0:89b318e49395 | 61 | } |
| fabeltranm | 0:89b318e49395 | 62 | |
| fabeltranm | 0:89b318e49395 | 63 | void debug_m(char *s , ... ){ |
| fabeltranm | 0:89b318e49395 | 64 | #if DEBUG |
| fabeltranm | 0:89b318e49395 | 65 | command.printf(s); |
| fabeltranm | 0:89b318e49395 | 66 | #endif |
| fabeltranm | 0:89b318e49395 | 67 | } |
