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@3:e43babb84ff3, 2018-09-09 (annotated)
- Committer:
- MigueAut
- Date:
- Sun Sep 09 01:02:43 2018 +0000
- Revision:
- 3:e43babb84ff3
- Parent:
- 2:6e6157daf08b
3 MOTORES
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; |
| MigueAut | 3:e43babb84ff3 | 23 | case 0x02: moving(); break; |
| MigueAut | 3:e43babb84ff3 | 24 | case 0x03: moving(); break; |
| MigueAut | 2:6e6157daf08b | 25 | default: debug_m("error de comando. \n");break ; |
| fabeltranm | 0:89b318e49395 | 26 | } |
| fabeltranm | 0:89b318e49395 | 27 | } |
| fabeltranm | 0:89b318e49395 | 28 | } |
| fabeltranm | 0:89b318e49395 | 29 | |
| fabeltranm | 0:89b318e49395 | 30 | |
| fabeltranm | 0:89b318e49395 | 31 | |
| fabeltranm | 0:89b318e49395 | 32 | uint32_t read_command() |
| fabeltranm | 0:89b318e49395 | 33 | { |
| fabeltranm | 1:526bdd5faa37 | 34 | // retorna los byte recibidos concatenados en un entero, |
| fabeltranm | 0:89b318e49395 | 35 | |
| fabeltranm | 1:526bdd5faa37 | 36 | |
| fabeltranm | 1:526bdd5faa37 | 37 | |
| fabeltranm | 1:526bdd5faa37 | 38 | char intc=command.getc(); |
| fabeltranm | 0:89b318e49395 | 39 | |
| MigueAut | 3:e43babb84ff3 | 40 | while(intc != '<' ) |
| fabeltranm | 1:526bdd5faa37 | 41 | intc=command.getc(); |
| MigueAut | 2:6e6157daf08b | 42 | return command.getc(); |
| fabeltranm | 0:89b318e49395 | 43 | } |
| fabeltranm | 1:526bdd5faa37 | 44 | |
| fabeltranm | 1:526bdd5faa37 | 45 | |
| fabeltranm | 0:89b318e49395 | 46 | void init_serial() |
| fabeltranm | 0:89b318e49395 | 47 | { |
| fabeltranm | 0:89b318e49395 | 48 | command.baud(9600); |
| fabeltranm | 0:89b318e49395 | 49 | } |
| fabeltranm | 0:89b318e49395 | 50 | |
| fabeltranm | 0:89b318e49395 | 51 | |
| fabeltranm | 1:526bdd5faa37 | 52 | void moving(){ |
| fabeltranm | 1:526bdd5faa37 | 53 | debug_m("se inicia el comado mover..\n"); |
| fabeltranm | 0:89b318e49395 | 54 | |
| fabeltranm | 1:526bdd5faa37 | 55 | char nmotor=command.getc(); |
| fabeltranm | 1:526bdd5faa37 | 56 | char grados=command.getc(); |
| MigueAut | 3:e43babb84ff3 | 57 | debug_m("SE MUEVE EL MOTOR %d, EN %d GRADOS ..\n", nmotor,grados ); |
| fabeltranm | 1:526bdd5faa37 | 58 | char endc=command.getc(); |
| fabeltranm | 1:526bdd5faa37 | 59 | mover_ser(nmotor,grados); |
| MigueAut | 2:6e6157daf08b | 60 | |
| MigueAut | 2:6e6157daf08b | 61 | debug_m("fin del comado MOVER ..\n"); |
| fabeltranm | 0:89b318e49395 | 62 | |
| fabeltranm | 0:89b318e49395 | 63 | } |
| fabeltranm | 0:89b318e49395 | 64 | |
| fabeltranm | 0:89b318e49395 | 65 | void debug_m(char *s , ... ){ |
| fabeltranm | 0:89b318e49395 | 66 | #if DEBUG |
| fabeltranm | 0:89b318e49395 | 67 | command.printf(s); |
| fabeltranm | 0:89b318e49395 | 68 | #endif |
| fabeltranm | 0:89b318e49395 | 69 | } |
