Testa o Joystick Shield V2.4
Revision 0:e75be3142dd1, committed 2018-03-14
- Comitter:
- afm76
- Date:
- Wed Mar 14 00:17:25 2018 +0000
- Child:
- 1:150923afdc8a
- Commit message:
- Testa o Joystick Shield V2.4
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Terminal.lib Wed Mar 14 00:17:25 2018 +0000 @@ -0,0 +1,1 @@ +http://os.mbed.com/users/simon/code/Terminal/#85184c13476c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Wed Mar 14 00:17:25 2018 +0000
@@ -0,0 +1,99 @@
+#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);
+ }
+}
+
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Wed Mar 14 00:17:25 2018 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/aa5281ff4a02 \ No newline at end of file