mbedbidos
/
recoge_manzanas_333
falta verificar cambio de joystick a accel
Diff: recoge_manzanas.cpp
- Revision:
- 5:f8ca9f670abe
- Parent:
- 4:3426b2472f99
--- a/recoge_manzanas.cpp Mon Nov 19 06:25:35 2018 +0000 +++ b/recoge_manzanas.cpp Thu Nov 22 09:00:51 2018 +0000 @@ -1,7 +1,7 @@ // Read from I2C slave at address 0x62 #include "mbed.h" - +#include "Ticker.h" #include "MPU6050.h" Serial command(USBTX,USBRX); //habilitar la comunicacion serial a traves del puerto usb. @@ -37,38 +37,24 @@ //-------------------------------------------------- //-------------------TICKER------------------------ //-------------------------------------------------- -void attime() { +void attime() +{ blink(); - //boton(); - }; + boton(); +}; //-------------------------------------------------- //-------------------BOTON------------------------ //-------------------------------------------------- void boton() { - int x=0; - while(1) - { - if (pulsador == 1) - x=0; - else + if (pulsador == 0) { - command.printf("Button pressed %d\n", x); - x++; - if(x>20) - { - for(int i=0; i<5;i++) - { - //led = !led; // Toggle the LED state - _boton=!_boton; - wait(0.2); - } - x=0; - } + command.printf("Button pressed %b\n", _boton); + _boton=!_boton; } - } } + //-------------------------------------------------- //-------------------SPI------------------------ //-------------------------------------------------- @@ -150,6 +136,7 @@ sendSPI(fil,0); if(fil==fila) sendSPI(fila,columna); + wait(0.05); } //-------------------------------------------------- @@ -250,7 +237,7 @@ //-------------------------------------------------- int velocidad(float _acc[3]) { - int vel,x=3,y=5; // + int vel,x=1,y=2; // int acc[3]; acc[0]=(int)_acc[0]; acc[1]=(int)_acc[1]; @@ -279,12 +266,10 @@ float _acc[3]; //command.printf("Accelerometer: \t X= %f, \t Y= %f, \t Z=%f \n", acc[0],acc[1],acc[2]); //command.printf("Gyroscope: \t X= %f, \t Y= %f, \t Z=%f \n", gyro[0],gyro[1],gyro[2]); - if(_boton==0) + if(_boton==1) { x=((int)(in1.read()*-650))+13; y=((int)(in2.read()*-650))+13; - //x=-x; - //y=-y; acc[0]=x; acc[1]=y; command.printf("Joystick: \t X= %d, \t Y= %d, \n", x,y); @@ -369,7 +354,7 @@ int main () { int guarda_linea,x=0; - timer.attach(&attime, 0.3); + timer.attach(&attime, 0.1); test(); borrar(); sendSPI(fila,columna);