Servo script + magnet driver for biorobotics project in Uni. Made by Teun van der Molen
Dependencies: MODSERIAL Servo mbed
main.cpp@2:37d109555c95, 2015-10-19 (annotated)
- Committer:
- teunman
- Date:
- Mon Oct 19 10:00:03 2015 +0000
- Revision:
- 2:37d109555c95
- Parent:
- 1:26baa438620b
latest version of servo. Cleaned up some documentation;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
teunman | 0:05ecf16dcb7b | 1 | #include "mbed.h" |
teunman | 1:26baa438620b | 2 | #include "Servo.h" |
teunman | 0:05ecf16dcb7b | 3 | |
teunman | 1:26baa438620b | 4 | |
teunman | 1:26baa438620b | 5 | DigitalOut green(LED2); //The led is on with the magnet |
teunman | 1:26baa438620b | 6 | DigitalOut magnet(D2); //magnet is defined on D2 |
teunman | 1:26baa438620b | 7 | DigitalIn knop(SW2); //The button used to cycle the entire pick up sequence |
teunman | 1:26baa438620b | 8 | |
teunman | 1:26baa438620b | 9 | |
teunman | 0:05ecf16dcb7b | 10 | int main() |
teunman | 0:05ecf16dcb7b | 11 | { |
teunman | 1:26baa438620b | 12 | |
teunman | 2:37d109555c95 | 13 | Servo swagvo(D4); //devine the port for controlling the servo (this cannot be a PWM port (i think) !!!) |
teunman | 1:26baa438620b | 14 | int down = 0; //counter |
teunman | 1:26baa438620b | 15 | green = 1; |
teunman | 1:26baa438620b | 16 | |
teunman | 2:37d109555c95 | 17 | swagvo.Enable(1500,20000); //turning on the servo (starting position,frequency (50 Hz do not change!!!)) |
teunman | 1:26baa438620b | 18 | // 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 |
teunman | 1:26baa438620b | 19 | |
teunman | 1:26baa438620b | 20 | while(true) { |
teunman | 1:26baa438620b | 21 | |
teunman | 1:26baa438620b | 22 | |
teunman | 1:26baa438620b | 23 | |
teunman | 1:26baa438620b | 24 | |
teunman | 1:26baa438620b | 25 | |
teunman | 1:26baa438620b | 26 | if (knop == 0 and down == 0){ |
teunman | 1:26baa438620b | 27 | swagvo.SetPosition(650); //lower wire |
teunman | 1:26baa438620b | 28 | wait(1); |
teunman | 1:26baa438620b | 29 | green = 0; |
teunman | 1:26baa438620b | 30 | magnet = 1; //attach piece |
teunman | 1:26baa438620b | 31 | wait(1); |
teunman | 1:26baa438620b | 32 | swagvo.SetPosition(2350); //raise wire |
teunman | 1:26baa438620b | 33 | down = 1; |
teunman | 1:26baa438620b | 34 | } |
teunman | 1:26baa438620b | 35 | |
teunman | 1:26baa438620b | 36 | else if (knop == 0 and down == 1){ |
teunman | 1:26baa438620b | 37 | swagvo.SetPosition(650); //lower wire |
teunman | 1:26baa438620b | 38 | wait(1); |
teunman | 1:26baa438620b | 39 | green = 1; |
teunman | 1:26baa438620b | 40 | magnet = 0; //detach piece |
teunman | 1:26baa438620b | 41 | wait(1); |
teunman | 1:26baa438620b | 42 | swagvo.SetPosition(2350); //raise wire |
teunman | 1:26baa438620b | 43 | down = 0; //reset |
teunman | 1:26baa438620b | 44 | } |
teunman | 1:26baa438620b | 45 | |
teunman | 1:26baa438620b | 46 | } |
teunman | 1:26baa438620b | 47 | } |
teunman | 1:26baa438620b | 48 | |
teunman | 1:26baa438620b | 49 |