![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Servo
Dependencies: mbed MODSERIAL Servo FastPWM
main.cpp@10:1754b6220c7a, 2019-10-28 (annotated)
- Committer:
- s1923196
- Date:
- Mon Oct 28 17:18:32 2019 +0000
- Revision:
- 10:1754b6220c7a
- Parent:
- 8:3990a8c4ccea
- Child:
- 11:bb036c288cd7
waarden 500-2400
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
s1923196 | 10:1754b6220c7a | 1 | |
s1923196 | 10:1754b6220c7a | 2 | #include "Servo.h" |
AnkePost | 0:60a8a60074a7 | 3 | #include "mbed.h" |
s1923196 | 10:1754b6220c7a | 4 | #include "FastPWM.h" |
AnkePost | 3:91b8945b659d | 5 | |
AnkePost | 0:60a8a60074a7 | 6 | Serial pc(USBTX, USBRX); |
s1923196 | 10:1754b6220c7a | 7 | Servo mijnServo(D7); |
s1923196 | 10:1754b6220c7a | 8 | double pos = 0; |
s1923196 | 10:1754b6220c7a | 9 | double target; |
s1923196 | 10:1754b6220c7a | 10 | int main(void) |
s1923196 | 10:1754b6220c7a | 11 | {mijnServo.Enable(1500,20000); |
s1923196 | 10:1754b6220c7a | 12 | wait(1); |
s1923196 | 10:1754b6220c7a | 13 | for(pos = 2400; pos >=500; pos-=50) |
s1923196 | 10:1754b6220c7a | 14 | { |
s1923196 | 10:1754b6220c7a | 15 | target = pos/180; |
s1923196 | 10:1754b6220c7a | 16 | mijnServo.SetPosition(pos); |
s1923196 | 10:1754b6220c7a | 17 | pc.printf("De servo staat op %f graden.\n\r", pos); |
s1923196 | 10:1754b6220c7a | 18 | wait(0.1); |
s1923196 | 10:1754b6220c7a | 19 | } |
s1923196 | 10:1754b6220c7a | 20 | for(pos = 500; pos <= 2400; pos += 50) |
s1923196 | 10:1754b6220c7a | 21 | { |
s1923196 | 10:1754b6220c7a | 22 | target = pos/180; |
s1923196 | 10:1754b6220c7a | 23 | mijnServo.SetPosition(pos); |
s1923196 | 10:1754b6220c7a | 24 | pc.printf("De servo staat op %f graden.\n\r", pos); |
s1923196 | 10:1754b6220c7a | 25 | wait(0.1); |
s1923196 | 10:1754b6220c7a | 26 | } |
s1923196 | 10:1754b6220c7a | 27 | while(true); |
s1923196 | 10:1754b6220c7a | 28 | |
s1923196 | 10:1754b6220c7a | 29 | } |