![](/media/cache/group/9e3cc099b3b04bca937a1cca1da81b19.jpg.50x50_q85.jpg)
servo motor werkt eindelijk!!!! wiehoe!!!
Dependencies: mbed QEI Servo HIDScope biquadFilter MODSERIAL FastPWM
main.cpp@3:f30c2ded1a58, 2019-10-29 (annotated)
- Committer:
- IsaRobin
- Date:
- Tue Oct 29 20:33:45 2019 +0000
- Revision:
- 3:f30c2ded1a58
- Parent:
- 2:f92eadfd1a27
- Child:
- 4:d3e8ec68ff97
servo eindelijk werkend wiehoeeee!!!!;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jasperkessels | 0:009a005982e5 | 1 | /* servo motor program - biorbotics groep 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 | |
jasperkessels | 0:009a005982e5 | 8 | |
IsaRobin | 3:f30c2ded1a58 | 9 | |
jasperkessels | 0:009a005982e5 | 10 | MODSERIAL pc(USBTX, USBRX); |
IsaRobin | 3:f30c2ded1a58 | 11 | Servo myservo(D3); |
IsaRobin | 3:f30c2ded1a58 | 12 | |
IsaRobin | 3:f30c2ded1a58 | 13 | |
IsaRobin | 3:f30c2ded1a58 | 14 | //Buttons |
IsaRobin | 3:f30c2ded1a58 | 15 | InterruptIn button2(SW2); |
IsaRobin | 3:f30c2ded1a58 | 16 | InterruptIn button3(SW3); |
IsaRobin | 1:1b33fd02e6b1 | 17 | |
IsaRobin | 1:1b33fd02e6b1 | 18 | |
IsaRobin | 3:f30c2ded1a58 | 19 | void kantelheen() |
IsaRobin | 3:f30c2ded1a58 | 20 | { |
jasperkessels | 0:009a005982e5 | 21 | |
IsaRobin | 3:f30c2ded1a58 | 22 | myservo.SetPosition(2000); |
IsaRobin | 3:f30c2ded1a58 | 23 | pc.printf("heeft gekanteld heen.\n.\r"); |
IsaRobin | 3:f30c2ded1a58 | 24 | |
IsaRobin | 3:f30c2ded1a58 | 25 | } |
IsaRobin | 3:f30c2ded1a58 | 26 | |
IsaRobin | 3:f30c2ded1a58 | 27 | void kantelterug() |
IsaRobin | 3:f30c2ded1a58 | 28 | { |
IsaRobin | 3:f30c2ded1a58 | 29 | myservo.SetPosition(1000); |
IsaRobin | 3:f30c2ded1a58 | 30 | pc.printf("heeft terug gekanteld .\n.\r"); |
IsaRobin | 3:f30c2ded1a58 | 31 | |
IsaRobin | 3:f30c2ded1a58 | 32 | } |
jasperkessels | 0:009a005982e5 | 33 | |
jasperkessels | 0:009a005982e5 | 34 | int main() |
jasperkessels | 0:009a005982e5 | 35 | { |
IsaRobin | 1:1b33fd02e6b1 | 36 | pc.baud(115200); |
IsaRobin | 1:1b33fd02e6b1 | 37 | pc.printf("starting main .\r.\n"); |
IsaRobin | 3:f30c2ded1a58 | 38 | myservo.Enable(1000,20000); |
IsaRobin | 3:f30c2ded1a58 | 39 | |
IsaRobin | 3:f30c2ded1a58 | 40 | button2.rise(kantelheen); |
IsaRobin | 3:f30c2ded1a58 | 41 | button3.rise(kantelterug); |
jasperkessels | 0:009a005982e5 | 42 | |
jasperkessels | 0:009a005982e5 | 43 | while(true) { |
IsaRobin | 3:f30c2ded1a58 | 44 | pc.printf("weer begonnen aan mijn main"); |
IsaRobin | 3:f30c2ded1a58 | 45 | wait(2); |
IsaRobin | 3:f30c2ded1a58 | 46 | |
IsaRobin | 3:f30c2ded1a58 | 47 | |
IsaRobin | 3:f30c2ded1a58 | 48 | } |
IsaRobin | 3:f30c2ded1a58 | 49 | } |
IsaRobin | 3:f30c2ded1a58 | 50 | /* pc.printf("starting.\r.\n"); |
IsaRobin | 3:f30c2ded1a58 | 51 | |
IsaRobin | 2:f92eadfd1a27 | 52 | for (int pos = 1410; pos < 1590; pos += 5) { |
jasperkessels | 0:009a005982e5 | 53 | myservo.SetPosition(pos); |
jasperkessels | 0:009a005982e5 | 54 | wait_ms(20); |
jasperkessels | 0:009a005982e5 | 55 | } |
IsaRobin | 2:f92eadfd1a27 | 56 | pc.printf("kant 1.\r.\n"); |
IsaRobin | 2:f92eadfd1a27 | 57 | for (int pos = 1590; pos > 1410; pos -= 5) { |
jasperkessels | 0:009a005982e5 | 58 | myservo.SetPosition(pos); |
jasperkessels | 0:009a005982e5 | 59 | wait_ms(20); |
jasperkessels | 0:009a005982e5 | 60 | } |
IsaRobin | 2:f92eadfd1a27 | 61 | pc.printf("kant 2.\r.\n"); |
jasperkessels | 0:009a005982e5 | 62 | } |
IsaRobin | 3:f30c2ded1a58 | 63 | */ |
jasperkessels | 0:009a005982e5 | 64 | |
jasperkessels | 0:009a005982e5 | 65 | |
jasperkessels | 0:009a005982e5 | 66 | |
IsaRobin | 3:f30c2ded1a58 | 67 |