jhonatan angel
/
Arana
abrayan
main.cpp@2:3007b3c06d2c, 2018-09-11 (annotated)
- Committer:
- angel123
- Date:
- Tue Sep 11 01:27:25 2018 +0000
- Revision:
- 2:3007b3c06d2c
- Parent:
- 1:526bdd5faa37
- Child:
- 6:8d7f6fe73ed1
Entrega_Primer_Corte
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 | #include "main.h" |
fabeltranm | 0:89b318e49395 | 3 | |
fabeltranm | 0:89b318e49395 | 4 | Serial command(USBTX, USBRX); |
fabeltranm | 0:89b318e49395 | 5 | |
fabeltranm | 0:89b318e49395 | 6 | int main() { |
fabeltranm | 0:89b318e49395 | 7 | init_servo(); |
fabeltranm | 0:89b318e49395 | 8 | init_serial(); |
fabeltranm | 1:526bdd5faa37 | 9 | |
fabeltranm | 0:89b318e49395 | 10 | debug_m("inicio \n"); |
fabeltranm | 0:89b318e49395 | 11 | uint32_t read_cc; |
fabeltranm | 0:89b318e49395 | 12 | while(1) |
fabeltranm | 0:89b318e49395 | 13 | { |
fabeltranm | 0:89b318e49395 | 14 | read_cc=read_command(); |
angel123 | 2:3007b3c06d2c | 15 | |
angel123 | 2:3007b3c06d2c | 16 | switch (read_cc) |
angel123 | 2:3007b3c06d2c | 17 | { |
angel123 | 2:3007b3c06d2c | 18 | case 0x01: moving(); |
angel123 | 2:3007b3c06d2c | 19 | break; |
angel123 | 2:3007b3c06d2c | 20 | |
angel123 | 2:3007b3c06d2c | 21 | default: debug_m("error de comando.\n"); |
angel123 | 2:3007b3c06d2c | 22 | break ; |
fabeltranm | 0:89b318e49395 | 23 | } |
fabeltranm | 0:89b318e49395 | 24 | } |
fabeltranm | 0:89b318e49395 | 25 | } |
fabeltranm | 0:89b318e49395 | 26 | |
fabeltranm | 0:89b318e49395 | 27 | |
fabeltranm | 0:89b318e49395 | 28 | |
fabeltranm | 0:89b318e49395 | 29 | uint32_t read_command() |
fabeltranm | 0:89b318e49395 | 30 | { |
fabeltranm | 1:526bdd5faa37 | 31 | char intc=command.getc(); |
fabeltranm | 0:89b318e49395 | 32 | |
angel123 | 2:3007b3c06d2c | 33 | while(intc != 0xff) |
fabeltranm | 1:526bdd5faa37 | 34 | intc=command.getc(); |
angel123 | 2:3007b3c06d2c | 35 | return command.getc(); |
fabeltranm | 0:89b318e49395 | 36 | } |
fabeltranm | 1:526bdd5faa37 | 37 | |
fabeltranm | 1:526bdd5faa37 | 38 | |
fabeltranm | 0:89b318e49395 | 39 | void init_serial() |
fabeltranm | 0:89b318e49395 | 40 | { |
fabeltranm | 0:89b318e49395 | 41 | command.baud(9600); |
fabeltranm | 0:89b318e49395 | 42 | } |
fabeltranm | 0:89b318e49395 | 43 | |
fabeltranm | 0:89b318e49395 | 44 | |
angel123 | 2:3007b3c06d2c | 45 | void moving() |
angel123 | 2:3007b3c06d2c | 46 | { |
fabeltranm | 1:526bdd5faa37 | 47 | debug_m("se inicia el comado mover..\n"); |
fabeltranm | 1:526bdd5faa37 | 48 | char nmotor=command.getc(); |
fabeltranm | 1:526bdd5faa37 | 49 | char grados=command.getc(); |
fabeltranm | 1:526bdd5faa37 | 50 | char endc=command.getc(); |
fabeltranm | 1:526bdd5faa37 | 51 | mover_ser(nmotor,grados); |
angel123 | 2:3007b3c06d2c | 52 | debug_m("fin del comado guardar..\n"); |
fabeltranm | 0:89b318e49395 | 53 | } |
fabeltranm | 0:89b318e49395 | 54 | |
fabeltranm | 0:89b318e49395 | 55 | void debug_m(char *s , ... ){ |
fabeltranm | 0:89b318e49395 | 56 | #if DEBUG |
fabeltranm | 0:89b318e49395 | 57 | command.printf(s); |
fabeltranm | 0:89b318e49395 | 58 | #endif |
fabeltranm | 0:89b318e49395 | 59 | } |