LAB

Dependencies:   mbed

Fork of LAB11_Oppgave2 by EL-POM1001

Revision:
2:132db1b8730d
Parent:
1:d4624c8ba9f5
--- a/main.cpp	Mon Nov 09 13:48:59 2015 +0000
+++ b/main.cpp	Tue Dec 08 15:42:57 2015 +0000
@@ -3,6 +3,9 @@
 I2C i2cBus(PB_9, PB_8);
 
 Serial pc(SERIAL_TX, SERIAL_RX);
+DigitalOut LED(PA_5);
+PwmOut      servoMotor(PA_7);
+DigitalOut  direction(PA_6);
 
 #define NUNCHUK_8BIT_ADDR 0x52<<1  //   8-bit I2C slave address  = (  ( 7bit i2c address) <<  1  |  (read/write) bit 
 
@@ -61,10 +64,38 @@
     NunchukData nunchukData;
 
     initNunchuk();
+    direction=0;
     while(true) {
+        LED = 0;
+        if(nunchukData.bButtonC == 1) {
+            LED = 1;
+        }
         GetNunchukData(nunchukData);
         printf("x-yoy %3d,y-yoy %3d ",nunchukData.xStick,nunchukData.yStick );
+        printf("X-acc: %3d, Y-acc: %3d, Z-acc: %3d, knapp Z: %d, knapp C: %d",nunchukData.xAcc,nunchukData.yAcc, nunchukData.zAcc,nunchukData.bButtonZ, nunchukData.bButtonC );
         printf("\r\n");
+
+        if(nunchukData.xStick<139) {
+            servoMotor=nunchukData.xStick/139.0f;
+            direction=1;
+        } else if(nunchukData.xStick>139) {
+            servoMotor=nunchukData.xStick/139.0f;
+            direction=0;
+        }
+
+        if(nunchukData.bButtonZ==1) 
+        {
+            if(nunchukData.xAcc<600) 
+            {
+                servoMotor=nunchukData.xAcc/600.0f;
+                direction=0;
+            } 
+            if(nunchukData.xAcc>600); 
+            {
+                servoMotor=nunchukData.xAcc/600.0f;
+                direction=!direction;
+        }
+     }
+
     }
 }
-