CONTROL ARAÑA

Dependencies:   mbed

Fork of 01-04EntregaPrimerCorte by ferney alberto beltran molina

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 #include "main.h"
00004 
00005 
00006 
00007 
00008 Serial command(USBTX, USBRX);
00009 
00010 
00011 
00012 int main() {
00013     init_servo();
00014     init_serial();
00015 
00016     debug_m("inicio \n");
00017     uint32_t read_cc;
00018     while(1)
00019     {
00020         read_cc=read_command();
00021         switch (read_cc) {
00022             case  0x01: moving(); break;
00023          case  0x02: moving(); break;
00024          case  0x03: moving(); break;
00025             default: debug_m("error de comando.  \n");break ;      
00026         }
00027     }
00028 }
00029 
00030 
00031 
00032 uint32_t read_command()
00033 {
00034    // retorna los byte recibidos concatenados en un entero, 
00035    
00036 
00037     
00038     char intc=command.getc();
00039     
00040     while(intc != '<' )
00041         intc=command.getc();
00042     return command.getc();
00043 }
00044 
00045 
00046 void init_serial()
00047 {
00048     command.baud(9600);    
00049 }
00050 
00051 
00052 void moving(){
00053     debug_m("se inicia el comado mover..\n");    
00054     
00055     char nmotor=command.getc();
00056     char grados=command.getc();
00057     debug_m("SE MUEVE EL MOTOR %d, EN %d GRADOS ..\n", nmotor,grados );    
00058     char endc=command.getc();
00059     mover_ser(nmotor,grados); 
00060     
00061     debug_m("fin del comado MOVER ..\n");    
00062     
00063 }
00064 
00065 void debug_m(char *s , ... ){
00066     #if DEBUG
00067     command.printf(s);
00068     #endif  
00069 }