You should connect the L298N motor driver to specified pins and connect the dc motor to L298N's outputs.

Dependencies:   mbed

Fork of Nucleo_Ex04_USBPAD by woodstock .

Files at this revision

API Documentation at this revision

Comitter:
denizkcts
Date:
Fri Jan 06 18:09:52 2017 +0000
Parent:
0:b5f79b4f741d
Commit message:
?

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r b5f79b4f741d -r ce7659a938ce main.cpp
--- a/main.cpp	Tue Mar 15 11:39:04 2016 +0000
+++ b/main.cpp	Fri Jan 06 18:09:52 2017 +0000
@@ -3,26 +3,74 @@
 
 USBHostGamepad *pad;
 
-// LED
-DigitalOut red(PB_5);
-DigitalOut yellow(PA_10);
+
+
+DigitalOut in1(PA_10);
+DigitalOut in2(PB_5);
+PwmOut hiz(PB_4);
+//DigitalIn geriA(PA_2);
+//DigitalIn durX(PB_3);
 
 int main()
 {    
     // USB Gmaepad Initialize
     pad = new USBHostGamepad();
-    if (!pad->connect()) {
+    if (!pad->connect()) 
+    {
         printf("USB Gamepad not found.\r\n");
         while(1);
     }
-    
+
+    bool state1;
+    bool state2;
+    hiz.period_ms(1);
     while(1)
     {
         USBHost::poll();
+      /* if(pad->report[5] & 0x020)
+       {
+           hiz.write(0.01);
+       }*/
+   if(pad->report[5] & 0x02)//RB (SAĞA DÖNME)
+      { 
+       state1=1;
+       state2=0;
+          }
+         else if(pad->report[5] & 0x04)//LT(SOLA DÖNME)
+        {
+            state1=0;
+            state2=1;
+            }
         
-        red = pad->report[4] & 0x20;
-        yellow = pad->report[4] & 0x40;
-        
+         else if(pad->report[4] & 0x010)//X
+        {
+         
+         in1=state1;
+         in2=state2;
+         hiz.write(0.25f);   
+          }
+        else if(pad->report[4] & 0x020)//A
+        {in1=state1;
+         in2=state2;
+            hiz.write(0.5f);
+        }
+         else if(pad->report[4] & 0x040)//B
+        {in1=state1;
+         in2=state2;
+            hiz.write(0.75f);
+        }
+          else if(pad->report[4] & 0x80)//Y
+        {
+         in1=state1;
+         in2=state2;
+            hiz.write(0.95f);
+        }
+         else if(pad->report[5] & 0x010)//SELECT(STOP BUTONU)
+         {
+            hiz.write(0);
+            in1=0;
+            in2=0;
+        }
         printf("%02x %02x %02x %02x %02x %02x %02x %02x\r\n", pad->report[0],pad->report[1],pad->report[2],pad->report[3],pad->report[4],pad->report[5],pad->report[6],pad->report[7]);
         wait_ms(16);
     }