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-04_Primer_Avance by
Diff: main.cpp
- Revision:
- 5:6ca97bfe9406
- Parent:
- 4:ba51736778e1
diff -r ba51736778e1 -r 6ca97bfe9406 main.cpp
--- a/main.cpp Fri Sep 07 23:58:14 2018 +0000
+++ b/main.cpp Sat Oct 06 17:45:42 2018 +0000
@@ -1,22 +1,17 @@
#include "mbed.h"
-
#include "main.h"
-
#define MEM_SIZE 5
#define MEM_TYPE char
MEM_TYPE buffer[MEM_SIZE];
-
+Serial command(USBTX, USBRX); // Usar Serial PC USB
+//Serial command(PC_10,PC_11); //Tx, RX. Usar Bluetooth HC-06.
-Serial command(USBTX, USBRX);
DigitalIn button(USER_BUTTON);
-
int main() {
init_servo();
init_serial();
debug_m("inicio \n");
-
-
uint32_t read_cc;
while(1)
{
@@ -35,6 +30,19 @@
pares();
debug_m("Tc 2 Finalizado\n");
break;
+ case 0x03:
+ debug_m("Tc 3 Iniciado.. \n");
+ caminar();
+ debug_m("Tc 3 Finalizado\n");
+ break;
+ case 0x05:
+ debug_m("Tc 5 Centrar Iniciado.. \n");
+ centro(01);
+ centro(02);
+ centro(03);
+ centro(04);
+ debug_m("Tc 5 Centrar Finalizado\n");
+ break;
default: debug_m("Error de comando. \nSe espera entre 0x01 - 0x08 \n");break ;
}
}
@@ -52,14 +60,15 @@
inicio:
- while(buffer[0] != 0xFF ){
+ while(buffer[0] != 0xFF ){ //7B y 7D son { y }
buffer[0] = command.getc();
debug_m("comando inicio invalido \n");
}
-
- printf("inicio encontrado: %c \n", buffer[0] );
+ debug_m("comando inicio Valido \n");
+ char ini = buffer[0];
+ printf("inicio encontrado: %x \n", ini);
buffer[1] = command.getc();
if (buffer[1] != 0xFF && buffer[1] != 0xFD){
@@ -92,7 +101,8 @@
//intc=command.getc();
int tele = buffer[1];
- printf("Tele siguente: %c \n", tele );
+ char telec = buffer[1];
+ printf("Tele comando: %x \n", telec );
return tele;
@@ -111,9 +121,9 @@
debug_m("se inicia el comado mover..\n");
char nmotor = buffer[2];
- printf("Motor: %c \n", nmotor );
+ printf("Motor: %x \n", nmotor );
char grados = buffer[3];
- printf("Grados: %c \n", grados );
+ printf("Grados: %x \n", grados );
//char endc = buffer[4];
//printf("Cierre: %c \n", endc );
mover_ser(nmotor,grados);
@@ -125,17 +135,33 @@
debug_m("se inicia el comado pares..\n");
char par = buffer[2];
- printf("Par: %c \n", par );
+ printf("Par: %x \n", par );
char dire = buffer[3];
- printf("Dir: %c \n", dire );
+ printf("Dir: %x \n", dire );
char endcc = buffer[4];
- printf("Cierre: %c \n", endcc );
+ printf("Cierre: %x \n", endcc );
while(button == 0) {
mover_par(par,dire);
}
centro(par);
debug_m("fin del comado pares..\n");
}
+
+void caminar(){
+ debug_m("Caminando..\n");
+
+ char par = buffer[2];
+ printf("Par: %x \n", par );
+ char dire = buffer[3];
+ printf("Dir: %x \n", dire );
+ char endcc = buffer[4];
+ printf("Cierre: %x \n", endcc );
+ while(button == 0) {
+ mover_par(par,dire);
+ }
+ centro(par);
+ debug_m("Stop..\n");
+ }
void debug_m(char *s , ... ){
#if DEBUG
command.printf(s);
