Servo script + magnet driver for biorobotics project in Uni. Made by Teun van der Molen
Dependencies: MODSERIAL Servo mbed
main.cpp
- Committer:
- teunman
- Date:
- 2015-10-19
- Revision:
- 2:37d109555c95
- Parent:
- 1:26baa438620b
File content as of revision 2:37d109555c95:
#include "mbed.h" #include "Servo.h" 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() { Servo swagvo(D4); //devine the port for controlling the servo (this cannot be a PWM port (i think) !!!) int down = 0; //counter green = 1; swagvo.Enable(1500,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 } } }