Espelhinho

Dependencies:   mbed

Revision:
0:8335b58dce7d
diff -r 000000000000 -r 8335b58dce7d main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri May 03 01:03:18 2019 +0000
@@ -0,0 +1,106 @@
+#include "mbed.h"
+
+DigitalOut In1b(A0);
+DigitalOut In2b(A1);
+DigitalOut EnB(A4);
+
+DigitalOut In1a(D5);
+DigitalOut In2a(D4);
+DigitalOut EnA(D2);
+
+AnalogIn VJoyX(A3);
+AnalogIn VJoyY(A5);
+
+DigitalIn Botao(PC_13);
+
+
+int main () {
+    float JoyX = 1.6;
+    float JoyY = 1.6;
+    bool Re = 0;
+    
+    
+    while(1) {
+        
+        JoyX = 3.3*VJoyX;
+        JoyY = 3.3*VJoyY;
+        
+        printf("%1.2f, %1.2f\n\r",JoyX,JoyY);
+        printf("%B\n",Re);
+        
+        if (JoyX>2.0) {
+        //Mexer em X
+        EnA = 1;
+        In1a = 1;
+        In2a = 0;
+        wait(0.1);
+        
+        }
+        
+        if (JoyX<1.0) {
+            
+        //Inversão em X
+        EnA = 1;
+        In1a = 0;
+        In2a = 1;
+        wait(0.1);   
+        
+        }
+        
+        if ((JoyX>1.0) and (JoyX <2.0)) {
+        
+        //Desligar X
+        EnA = 1;
+        In1a = 1;
+        In2a = 1;
+        wait(0.1); 
+           
+        }
+        
+        if (JoyY>2.0) {
+           
+        //Mexer em Y
+        EnB = 1;
+        In1b = 1;
+        In2b = 0;
+        wait(0.1);
+        
+        }
+        
+        if (JoyY<1.0) {
+            
+        //Inversão em Y
+        EnB = 1;
+        In1b = 0;
+        In2b = 1;
+        wait(0.1); 
+        
+        }
+        
+        if ((JoyY>1.0) and (JoyY <2.0)) { 
+        
+        //Desligar Y
+        EnB = 1;
+        In1b = 1;
+        In2b = 1;
+        wait(0.1); 
+        
+        }
+        Re=Botao;
+        
+        if (Re==0) {
+        //Mexer em X
+        EnB = 1;
+        In1b = 0;
+        In2b = 1;
+        wait(1);  
+        
+        In1b = 1;
+        In2b = 0;
+        wait(1);    
+         
+         }
+            
+                }
+        
+}