NUEVO
Fork of 01-04EntregaPrimerCorte by
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "mbed.h" 00002 00003 #include "main.h" 00004 00005 00006 00007 00008 Serial command(USBTX, USBRX); 00009 00010 #define MAXDAT 3 00011 #define TIPO_COMM 0 00012 #define NUM_MOTOR 1 00013 #define NUM_GRADOS 2 00014 00015 00016 uint8_t dat[MAXDAT]={0,0,0}; 00017 00018 00019 00020 int main() { 00021 init_servo(); 00022 init_serial(); 00023 00024 debug_m("inicio \n"); 00025 uint32_t read_cc; 00026 while(1) 00027 { 00028 while(read_command()==0); 00029 switch (dat[TIPO_COMM]) { 00030 case 0x01: moving(); break; 00031 default: debug_m("prueba comando. "); 00032 break ; 00033 } 00034 } 00035 } 00036 00037 00038 00039 uint32_t read_command() 00040 { 00041 // retorna los byte recibidos concatenados en un entero, 00042 00043 00044 00045 char intc=command.getc(); 00046 00047 while(intc != '<') 00048 intc=command.getc(); 00049 00050 for (int i =0;i<MAXDAT;i++) 00051 dat[i]=command.getc(); 00052 00053 intc=command.getc(); 00054 00055 if(intc != '>'){ 00056 debug_m("error de comando no se recibe bien ..\n"); 00057 return 0; 00058 } 00059 return 1; 00060 } 00061 00062 00063 void init_serial() 00064 { 00065 command.baud(9600); 00066 } 00067 00068 00069 void moving(){ 00070 debug_m("se inicia el comado mover..\n"); 00071 00072 char nmotor=dat[NUM_MOTOR]; 00073 char grados=dat[NUM_GRADOS]; 00074 mover_ser(nmotor,grados); 00075 debug_m("fin del comado ..\n"); 00076 00077 } 00078 00079 void debug_m(char *s , ... ){ 00080 #if DEBUG 00081 command.printf(s); 00082 #endif 00083 }
Generated on Wed Jul 27 2022 00:45:30 by
1.7.2
