Mateo Morales / Mbed 2 deprecated Joystick

Dependencies:   mbed

main.cpp

Committer:
Mateom0104
Date:
2019-04-15
Revision:
0:050768391650

File content as of revision 0:050768391650:

#include "mbed.h"
 
Serial pc(SERIAL_TX, SERIAL_RX); 
 
AnalogIn p1(A0); // entrada analoga potenciometro x
AnalogIn p2(A1);// entrada analoga potenciometro y
AnalogIn boton(A2);// entrada analoga boton

float potx; //potenciometro en x
float poty;  // potenciometro en y
float boton1; // boton 
    
    
DigitalOut led(LED1);

void leer(void);

int main() {
    pc.baud(9600);
    
       while(1) 
       {
        leer();
          while(boton1==1)// espera hasta que se levante el boton
          {
            leer(); 
            if(boton1==0) // espera hasta precionar el boton
            led=!led;  // prende y apaga led
          }
       }    
}


void leer()
{
        potx = p1.read(); // Lee potenciometr0 x, valores entre 0.0 y 1.0
        pc.printf("%f  ",potx);
        
        
        poty = p2.read(); // Lee potenciometro y, valores entre 0.0 y 1.0
        pc.printf("   %f  ",poty);
        
        boton1 = boton.read(); // Lee boton, valores entre 0.0 y 1.0 (valor<0.005 oprimido)
        pc.printf("   %f \n ",boton1);
        
        if (boton1<0.005) // si el valor es mas pe  queño que 0.005 esa presionado
        boton1=0;
        else
        boton1=1;   
        
        // wait(0.4); // si se quiere revisar valor leido por serial quietar comentario para q sea mas lento en el terminal
        
}