Zhen Liu
/
HW2_P6
problem 6 for HW 2
Fork of Servo_HelloWorld by
main.cpp@2:184c8630e678, 2015-02-18 (annotated)
- Committer:
- lzzcd001
- Date:
- Wed Feb 18 14:52:18 2015 +0000
- Revision:
- 2:184c8630e678
- Parent:
- 1:40d2fd0b99e6
problem 6 for HW 2
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
simon | 1:40d2fd0b99e6 | 1 | // Hello World to sweep a servo through its full range |
simon | 1:40d2fd0b99e6 | 2 | |
simon | 1:40d2fd0b99e6 | 3 | #include "mbed.h" |
simon | 1:40d2fd0b99e6 | 4 | #include "Servo.h" |
simon | 1:40d2fd0b99e6 | 5 | |
simon | 1:40d2fd0b99e6 | 6 | Servo myservo(p21); |
simon | 1:40d2fd0b99e6 | 7 | |
simon | 1:40d2fd0b99e6 | 8 | int main() { |
lzzcd001 | 2:184c8630e678 | 9 | //for(float p=0; p<1.0; p += 0.1) { |
lzzcd001 | 2:184c8630e678 | 10 | // myservo = p; |
lzzcd001 | 2:184c8630e678 | 11 | // wait(0.2); |
lzzcd001 | 2:184c8630e678 | 12 | //} |
lzzcd001 | 2:184c8630e678 | 13 | for(float p=0; p<1; p += 0.1) { |
simon | 1:40d2fd0b99e6 | 14 | myservo = p; |
simon | 1:40d2fd0b99e6 | 15 | wait(0.2); |
simon | 1:40d2fd0b99e6 | 16 | } |
lzzcd001 | 2:184c8630e678 | 17 | for(float p=1; p>0; p -= 0.1) { |
lzzcd001 | 2:184c8630e678 | 18 | myservo = p; |
lzzcd001 | 2:184c8630e678 | 19 | wait(0.2); |
lzzcd001 | 2:184c8630e678 | 20 | } |
lzzcd001 | 2:184c8630e678 | 21 | for(float p=0.2; p<0.8; p += 0.1) { |
lzzcd001 | 2:184c8630e678 | 22 | myservo = p+0.05; |
lzzcd001 | 2:184c8630e678 | 23 | wait(0.2); |
lzzcd001 | 2:184c8630e678 | 24 | myservo = p-0.05; |
lzzcd001 | 2:184c8630e678 | 25 | wait(0.2); |
lzzcd001 | 2:184c8630e678 | 26 | } |
simon | 1:40d2fd0b99e6 | 27 | } |