Testa o Joystick Shield V2.4

Dependencies:   Terminal mbed

main.cpp

Committer:
afm76
Date:
2018-03-18
Revision:
1:150923afdc8a
Parent:
0:e75be3142dd1

File content as of revision 1:150923afdc8a:

#include "mbed.h"
//#include "terminal.h"
/*------------------------------------------------------------------------------
Before to use this example, ensure that you an hyperterminal installed on your
computer. More info here: https://developer.mbed.org/handbook/Terminals

The default serial comm port uses the SERIAL_TX and SERIAL_RX pins (see their
definition in the PinNames.h file).

The default serial configuration in this case is 9600 bauds, 8-bit data, no parity

If you want to change the baudrate for example, you have to redeclare the
serial object in your code:

Serial pc(SERIAL_TX, SERIAL_RX);

Then, you can modify the baudrate and print like this:

pc.baud(115200);
pc.printf("Hello World !\n");
------------------------------------------------------------------------------*/
   
DigitalIn botao_A(D2);
DigitalIn botao_B(D3);
DigitalIn botao_C(D4);
DigitalIn botao_D(D5);
DigitalIn botao_E(D6);
DigitalIn botao_F(D7);
DigitalIn botao_K(D8);

AnalogIn eixo_X(A0);
AnalogIn eixo_Y(A1);

DigitalOut myled(LED1);
 
Serial pc(USBTX, USBRX);
 
int main() {
int a,b,c,d,e,f,k;
int i;
int x,y;
float u,w; 
pc.baud(9600);

a=b=c=d=e=f=k=0; //a=0,b=0,c=0,d=0,e=0,f=0,k=0;

//cls();
pc.printf("\f\n\r\t\t\t\t\t\tHello Analog World!!!");
pc.printf("\n\rStart\tA=%d,\tB=%d,\tC=%d,\tD=%d,\tE=%d,\tF=%d,\tK=%d,\tEixos<int>\tEixos<float>\tEixos<status>",a,b,c,d,e,f,k);
pc.printf("\n\rBotao\tA\tB\tC\tD\tE\tF\tK\tx\ty\tX\tY\n");

 
  while(1) {
    
    if (botao_A == 0) { // Botão usuário pressionado
      a++; 
    }
    if (botao_B == 0) { // Botão externo pressionado
      b++; 
    }
    if (botao_C == 0) { // Botão usuário pressionado
      c++; 
    }
    if (botao_D == 0) { // Botão usuário pressionado
      d++; 
    }
    if (botao_E == 0) { // Botão usuário pressionado
      e++; 
    }
    if (botao_F == 0) { // Botão usuário pressionado
      f++; 
    }
    if (botao_K == 0) { // Botão usuário pressionado
      k++; 
    }
//x=(int)eixo_X.read();
u=eixo_X.read();
//x=(int)u;
x=eixo_X.read()*255;    //Converte uma leitura do ADC em float para formato int e armazena na variável y.

w=eixo_Y.read();
y=eixo_Y.read()*255;    //Converte uma leitura do ADC em float para formato int e armazena na variável y.

pc.printf("\rValor\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%X \t%X \t%2.3f\t%2.3f",a,b,c,d,e,f,k,x,y,eixo_X.read(),eixo_Y.read());
                                                //Detecta a faixa em que o cursor do pot se encontra:
if (u>0.505){pc.printf(" X FWD ");}           //pot > 0.505V (comanda acionamento X proporcional para FRENTE);
else{   if (u<0.495){pc.printf(" X BWD ");}   //pot < 0.495V (comanda acionamento X proporcional para TRAS);
        else pc.printf(" X STOP");            //0.495V < pot < 0.505V (comanda acionamento X para permanecer PARADO).
     };   
if (w>0.505){pc.printf(" Y FWD \r");}           //pot > 0.505V (comanda acionamento Y proporcional para FRENTE);
else{   if (w<0.491){pc.printf(" Y BWD \r");}   //pot < 0.495V (comanda acionamento Y proporcional para TRAS);
        else pc.printf(" Y STOP\r");            //0.495V < pot < 0.505V (comanda acionamento Y para permanecer PARADO).
     };     

//    for (i = 1; i < 1000000; i+=1){}
      wait(0.2);
 }
}