Peter Knoben
/
Servo_control
Servo controller
main.cpp@0:1810c6beabf5, 2017-10-20 (annotated)
- Committer:
- peterknoben
- Date:
- Fri Oct 20 09:34:24 2017 +0000
- Revision:
- 0:1810c6beabf5
Servo controller
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
peterknoben | 0:1810c6beabf5 | 1 | #include "mbed.h" |
peterknoben | 0:1810c6beabf5 | 2 | #include "Servo.h" |
peterknoben | 0:1810c6beabf5 | 3 | |
peterknoben | 0:1810c6beabf5 | 4 | //------------------------------------------------------------------------------ |
peterknoben | 0:1810c6beabf5 | 5 | //------------------------------Servo Setup------------------------------------- |
peterknoben | 0:1810c6beabf5 | 6 | //------------------------------------------------------------------------------ |
peterknoben | 0:1810c6beabf5 | 7 | |
peterknoben | 0:1810c6beabf5 | 8 | Servo MyServo(D9); |
peterknoben | 0:1810c6beabf5 | 9 | InterruptIn But1(PTA4); |
peterknoben | 0:1810c6beabf5 | 10 | int k=0; |
peterknoben | 0:1810c6beabf5 | 11 | |
peterknoben | 0:1810c6beabf5 | 12 | //------------------------------------------------------------------------------ |
peterknoben | 0:1810c6beabf5 | 13 | //---------------------------Servo Controller----------------------------------- |
peterknoben | 0:1810c6beabf5 | 14 | //------------------------------------------------------------------------------ |
peterknoben | 0:1810c6beabf5 | 15 | |
peterknoben | 0:1810c6beabf5 | 16 | void servo_control (){ |
peterknoben | 0:1810c6beabf5 | 17 | if (k==0){ |
peterknoben | 0:1810c6beabf5 | 18 | MyServo = 0; |
peterknoben | 0:1810c6beabf5 | 19 | k=1; |
peterknoben | 0:1810c6beabf5 | 20 | } |
peterknoben | 0:1810c6beabf5 | 21 | else{ |
peterknoben | 0:1810c6beabf5 | 22 | MyServo = 2; |
peterknoben | 0:1810c6beabf5 | 23 | k=0; |
peterknoben | 0:1810c6beabf5 | 24 | } |
peterknoben | 0:1810c6beabf5 | 25 | } |
peterknoben | 0:1810c6beabf5 | 26 | |
peterknoben | 0:1810c6beabf5 | 27 | //------------------------------------------------------------------------------ |
peterknoben | 0:1810c6beabf5 | 28 | //-------------------------------Main Loop-------------------------------------- |
peterknoben | 0:1810c6beabf5 | 29 | //------------------------------------------------------------------------------ |
peterknoben | 0:1810c6beabf5 | 30 | |
peterknoben | 0:1810c6beabf5 | 31 | int main() |
peterknoben | 0:1810c6beabf5 | 32 | { |
peterknoben | 0:1810c6beabf5 | 33 | But1.rise(&servo_control); |
peterknoben | 0:1810c6beabf5 | 34 | while (1) {} |
peterknoben | 0:1810c6beabf5 | 35 | } |