servo motor werkt eindelijk!!!! wiehoe!!!
Dependencies: mbed QEI Servo HIDScope biquadFilter MODSERIAL FastPWM
main.cpp@5:e21d303d62d8, 2019-10-30 (annotated)
- Committer:
- IsaRobin
- Date:
- Wed Oct 30 13:02:28 2019 +0000
- Revision:
- 5:e21d303d62d8
- Parent:
- 4:d3e8ec68ff97
- Child:
- 6:69f112e63de9
servo motor final version met alleen knop sw2;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
IsaRobin | 4:d3e8ec68ff97 | 1 | /* servo motor program - biorbotics group 8 */ |
jasperkessels | 0:009a005982e5 | 2 | |
jasperkessels | 0:009a005982e5 | 3 | #include <Servo.h> |
jasperkessels | 0:009a005982e5 | 4 | #include <mbed.h> |
jasperkessels | 0:009a005982e5 | 5 | #include <math.h> /* cos */ |
jasperkessels | 0:009a005982e5 | 6 | #include <MODSERIAL.h> |
jasperkessels | 0:009a005982e5 | 7 | |
IsaRobin | 4:d3e8ec68ff97 | 8 | MODSERIAL pc(USBTX, USBRX); //connect pc |
IsaRobin | 4:d3e8ec68ff97 | 9 | Servo myservo(D3); //the servo motor is connected to pin D3 on the BioRobotics shield |
IsaRobin | 3:f30c2ded1a58 | 10 | |
IsaRobin | 5:e21d303d62d8 | 11 | //Button that will be used to control the servo motor |
IsaRobin | 5:e21d303d62d8 | 12 | InterruptIn button2(SW2); //when this button is pushed for the first time, the servo motor rotates to show the card to the user, when the button is pushed for the second time the servo motor rotates the card away from the user |
IsaRobin | 5:e21d303d62d8 | 13 | |
IsaRobin | 1:1b33fd02e6b1 | 14 | |
IsaRobin | 5:e21d303d62d8 | 15 | bool showcard=0; |
jasperkessels | 0:009a005982e5 | 16 | |
IsaRobin | 5:e21d303d62d8 | 17 | void changeservo() |
IsaRobin | 5:e21d303d62d8 | 18 | { |
IsaRobin | 5:e21d303d62d8 | 19 | if (showcard==1){ |
IsaRobin | 3:f30c2ded1a58 | 20 | myservo.SetPosition(2000); |
IsaRobin | 5:e21d303d62d8 | 21 | showcard=!showcard; |
IsaRobin | 5:e21d303d62d8 | 22 | } |
IsaRobin | 5:e21d303d62d8 | 23 | |
IsaRobin | 5:e21d303d62d8 | 24 | else { |
IsaRobin | 3:f30c2ded1a58 | 25 | myservo.SetPosition(1000); |
IsaRobin | 5:e21d303d62d8 | 26 | showcard=!showcard; |
IsaRobin | 5:e21d303d62d8 | 27 | } |
IsaRobin | 3:f30c2ded1a58 | 28 | } |
jasperkessels | 0:009a005982e5 | 29 | |
jasperkessels | 0:009a005982e5 | 30 | int main() |
jasperkessels | 0:009a005982e5 | 31 | { |
IsaRobin | 1:1b33fd02e6b1 | 32 | pc.baud(115200); |
IsaRobin | 3:f30c2ded1a58 | 33 | myservo.Enable(1000,20000); |
IsaRobin | 3:f30c2ded1a58 | 34 | |
IsaRobin | 5:e21d303d62d8 | 35 | button2.rise(changeservo); |
jasperkessels | 0:009a005982e5 | 36 | |
jasperkessels | 0:009a005982e5 | 37 | while(true) { |
IsaRobin | 5:e21d303d62d8 | 38 | |
IsaRobin | 3:f30c2ded1a58 | 39 | } |
IsaRobin | 3:f30c2ded1a58 | 40 | } |
jasperkessels | 0:009a005982e5 | 41 | |
jasperkessels | 0:009a005982e5 | 42 | |
jasperkessels | 0:009a005982e5 | 43 | |
IsaRobin | 3:f30c2ded1a58 | 44 | |
IsaRobin | 4:d3e8ec68ff97 | 45 |