LAB09_Oppgave3

Dependencies:   mbed

Fork of LAB09_Oppgave2 by EL-POM1001

Files at this revision

API Documentation at this revision

Comitter:
madmonkeyman82
Date:
Thu Oct 29 11:18:45 2015 +0000
Parent:
0:8f25416dc51e
Commit message:
first;

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 8f25416dc51e -r 89eecafc3c83 main.cpp
--- a/main.cpp	Tue Oct 27 19:02:10 2015 +0000
+++ b/main.cpp	Thu Oct 29 11:18:45 2015 +0000
@@ -1,6 +1,5 @@
 #include "mbed.h"
 
-InterruptIn userButton(PC_13);
 DigitalOut  userLed(PA_5);
 
 DigitalOut Vcc(PA_0);
@@ -10,22 +9,36 @@
 PwmOut      servoMotor(PA_7);
 DigitalOut  direction(PA_6);
 
-void pressed()
-{
-    userLed=!userLed;     // Toogle user led
-    direction=!direction; // Change motor direction
-}
-
 int main()
 {
-    userButton.fall(&pressed);
     servoMotor.period(.01);
 
     Vcc=1;
     Gnd=0;
-
+    direction=0;
+    
     while(1) {
-        servoMotor=aInn.read();
+        float pot = aInn.read();
+        if(pot > 0.45f && pot < 0.55f)
+        {
+            direction=0;
+            servoMotor = 0;
+            printf("NULL Pot er: %f Servo er: %f\n\r",pot, servoMotor.read());
+        } 
+        else if (pot < 0.45f) 
+        {
+            direction = 0;
+            userLed = 0;
+            servoMotor = 1-pot*2;
+            printf("CCW Pot er: %f Servo er: %f\n\r",pot, servoMotor.read());
+        } 
+        else if (pot > 0.55f) 
+        {
+            direction = 1;
+            userLed = 1;
+            servoMotor = 2-pot*2;
+            printf("CW Pot er: %f Servo er: %f\n\r",pot, servoMotor.read());
+        }  
     }
 
 }