Servo script + magnet driver for biorobotics project in Uni. Made by Teun van der Molen

Dependencies:   MODSERIAL Servo mbed

Revision:
1:26baa438620b
Parent:
0:05ecf16dcb7b
Child:
2:37d109555c95
--- a/main.cpp	Wed Sep 09 15:19:24 2015 +0000
+++ b/main.cpp	Mon Sep 28 14:27:06 2015 +0000
@@ -1,24 +1,50 @@
 #include "mbed.h"
-#include "HIDScope.h"
- 
-// Define the HIDScope and Ticker object
-HIDScope    scope(1);
-Ticker      scopeTimer;
+
+#include "Servo.h"
  
-// Read the analog input
-AnalogIn    an_in(A0);
- 
-// The data read and send function
-void scopeSend()
-{
-    scope.set(0,an_in.read());
-    scope.send();
-}
- 
+
+DigitalOut     green(LED2); //The led is on with the magnet
+DigitalOut      magnet(D2); //magnet is defined on D2
+DigitalIn       knop(SW2);  //The button used to cycle the entire pick up sequence
+
+
 int main()
 {
-    // Attach the data read and send function at 100 Hz
-    scopeTimer.attach_us(&scopeSend, 1e4);   
-    
-    while(1) { }
-}
\ No newline at end of file
+  
+       Servo swagvo(D4);    //devine the port for controlling the servo (this cannot be a PWM port !!!)
+       int down = 0;        //counter
+       green = 1;       
+       
+swagvo.Enable(2350,20000);      //turning on the servo (starting position,frequency (50 Hz do not change!!!))
+                                // The servo has the following positions (fully left: 650, center (1500), fully right (2350)) these values prevent the servo from grinding so do not exceed them
+
+    while(true) { 
+
+
+           
+         
+       
+       if (knop == 0 and down == 0){
+        swagvo.SetPosition(650);                //lower wire
+        wait(1);
+        green = 0;
+        magnet = 1;                             //attach piece
+        wait(1);
+        swagvo.SetPosition(2350);               //raise wire
+        down = 1;
+    }
+ 
+ else if (knop == 0 and down == 1){
+        swagvo.SetPosition(650);                //lower wire
+        wait(1);
+        green = 1;
+        magnet = 0;                             //detach piece
+        wait(1);
+        swagvo.SetPosition(2350);               //raise wire
+        down = 0;                               //reset
+    }
+        
+      }
+}
+
+