test servo

Dependencies:   mbed

Committer:
hayashiisme
Date:
Tue Jan 14 08:31:05 2014 +0000
Revision:
0:6d8bbd43c8e8
test servo

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hayashiisme 0:6d8bbd43c8e8 1 #include "mbed.h"
hayashiisme 0:6d8bbd43c8e8 2
hayashiisme 0:6d8bbd43c8e8 3 PwmOut servo1(p21);
hayashiisme 0:6d8bbd43c8e8 4 PwmOut servo2(p22);
hayashiisme 0:6d8bbd43c8e8 5
hayashiisme 0:6d8bbd43c8e8 6 #define waitsec 0.04
hayashiisme 0:6d8bbd43c8e8 7 #define start 900
hayashiisme 0:6d8bbd43c8e8 8 #define end 190
hayashiisme 0:6d8bbd43c8e8 9
hayashiisme 0:6d8bbd43c8e8 10 int main(){
hayashiisme 0:6d8bbd43c8e8 11 servo1.period_ms(20); // servo requires a 20ms period
hayashiisme 0:6d8bbd43c8e8 12 servo2.period_ms(20); // servo requires a 20ms period
hayashiisme 0:6d8bbd43c8e8 13 for(int i=0; i < 5; i++){
hayashiisme 0:6d8bbd43c8e8 14 for(int i = start; i < end; i += 10) {
hayashiisme 0:6d8bbd43c8e8 15 servo1.pulsewidth_us(i); // servo position determined by a pulsewidth between 1-2ms
hayashiisme 0:6d8bbd43c8e8 16 servo2.pulsewidth_us(i); // servo position determined by a pulsewidth between 1-2ms
hayashiisme 0:6d8bbd43c8e8 17 wait(waitsec);
hayashiisme 0:6d8bbd43c8e8 18 }
hayashiisme 0:6d8bbd43c8e8 19 for(int i = end; i > start; i -= 10) {
hayashiisme 0:6d8bbd43c8e8 20 servo1.pulsewidth_us(i); // servo position determined by a pulsewidth between 1-2ms
hayashiisme 0:6d8bbd43c8e8 21 servo2.pulsewidth_us(i); // servo position determined by a pulsewidth between 1-2ms
hayashiisme 0:6d8bbd43c8e8 22 wait(waitsec);
hayashiisme 0:6d8bbd43c8e8 23 }
hayashiisme 0:6d8bbd43c8e8 24 }
hayashiisme 0:6d8bbd43c8e8 25 }