DC motor and Servo
Dependencies: DC_Motor Servo mbed
Fork of Lab2_41 by
main.cpp@1:88e499bfdcc7, 2018-10-03 (annotated)
- Committer:
- Red_Nova_Six
- Date:
- Wed Oct 03 18:31:18 2018 +0000
- Revision:
- 1:88e499bfdcc7
- Parent:
- 0:5ea7adc7e9cf
- Child:
- 2:ecf535666eb3
the lab2_4;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Red_Nova_Six | 1:88e499bfdcc7 | 1 | |
Red_Nova_Six | 0:5ea7adc7e9cf | 2 | #include "mbed.h" |
Red_Nova_Six | 0:5ea7adc7e9cf | 3 | #include "Servo.h" |
Red_Nova_Six | 1:88e499bfdcc7 | 4 | #include "Motor.h" |
Red_Nova_Six | 0:5ea7adc7e9cf | 5 | |
Red_Nova_Six | 1:88e499bfdcc7 | 6 | Servo myservo(p21); |
Red_Nova_Six | 0:5ea7adc7e9cf | 7 | Servo myservo2(p22); |
Red_Nova_Six | 1:88e499bfdcc7 | 8 | Motor(PinName pwm, PinName fwd, PinName rev): |
Red_Nova_Six | 0:5ea7adc7e9cf | 9 | |
Red_Nova_Six | 1:88e499bfdcc7 | 10 | int i; |
Red_Nova_Six | 1:88e499bfdcc7 | 11 | |
Red_Nova_Six | 1:88e499bfdcc7 | 12 | int main() |
Red_Nova_Six | 0:5ea7adc7e9cf | 13 | { |
Red_Nova_Six | 1:88e499bfdcc7 | 14 | myservo.calibrate(0.0009,90); |
Red_Nova_Six | 1:88e499bfdcc7 | 15 | myservo2.calibrate(0.0009, 90); |
Red_Nova_Six | 0:5ea7adc7e9cf | 16 | |
Red_Nova_Six | 1:88e499bfdcc7 | 17 | while(1) { |
Red_Nova_Six | 1:88e499bfdcc7 | 18 | for( i=0; i<180; i++) { |
Red_Nova_Six | 1:88e499bfdcc7 | 19 | myservo = i/180.0; |
Red_Nova_Six | 1:88e499bfdcc7 | 20 | myservo2=(180.0-i)/180.0; |
Red_Nova_Six | 1:88e499bfdcc7 | 21 | wait(0.025); |
Red_Nova_Six | 1:88e499bfdcc7 | 22 | } |
Red_Nova_Six | 1:88e499bfdcc7 | 23 | for( i=180; i>0; i--) { |
Red_Nova_Six | 1:88e499bfdcc7 | 24 | myservo = i/180.0; |
Red_Nova_Six | 1:88e499bfdcc7 | 25 | myservo2=(180.0-i)/180.0; |
Red_Nova_Six | 1:88e499bfdcc7 | 26 | wait(0.025); |
Red_Nova_Six | 0:5ea7adc7e9cf | 27 | } |
Red_Nova_Six | 1:88e499bfdcc7 | 28 | } |
Red_Nova_Six | 1:88e499bfdcc7 | 29 | } |