Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp@0:c21b120b95fa, 2019-09-29 (annotated)
- Committer:
- chelseamar
- Date:
- Sun Sep 29 16:26:57 2019 +0000
- Revision:
- 0:c21b120b95fa
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
chelseamar | 0:c21b120b95fa | 1 | // Continuously sweep the servo through it's full range |
chelseamar | 0:c21b120b95fa | 2 | #include "mbed.h" |
chelseamar | 0:c21b120b95fa | 3 | #include "Servo.h" |
chelseamar | 0:c21b120b95fa | 4 | #include <iostream> |
chelseamar | 0:c21b120b95fa | 5 | |
chelseamar | 0:c21b120b95fa | 6 | Servo S1(D3);//old 1 |
chelseamar | 0:c21b120b95fa | 7 | Servo S3(D6);//old 2 |
chelseamar | 0:c21b120b95fa | 8 | Servo S5(D10);//old 3 |
chelseamar | 0:c21b120b95fa | 9 | Servo S2(D5);//old 4 |
chelseamar | 0:c21b120b95fa | 10 | Servo S6(D11);//old 5 |
chelseamar | 0:c21b120b95fa | 11 | Servo S4(D9);//old 6 |
chelseamar | 0:c21b120b95fa | 12 | |
chelseamar | 0:c21b120b95fa | 13 | //Servo servos[6]; |
chelseamar | 0:c21b120b95fa | 14 | |
chelseamar | 0:c21b120b95fa | 15 | int range=100.0; |
chelseamar | 0:c21b120b95fa | 16 | |
chelseamar | 0:c21b120b95fa | 17 | int main() { |
chelseamar | 0:c21b120b95fa | 18 | |
chelseamar | 0:c21b120b95fa | 19 | //Calibrate the motors |
chelseamar | 0:c21b120b95fa | 20 | S1.calibrate(0.001, 180); |
chelseamar | 0:c21b120b95fa | 21 | S3.calibrate(0.001, 180); |
chelseamar | 0:c21b120b95fa | 22 | S5.calibrate(0.00083, 180); |
chelseamar | 0:c21b120b95fa | 23 | S2.calibrate(0.001, 180); |
chelseamar | 0:c21b120b95fa | 24 | S6.calibrate(0.00084, 180); |
chelseamar | 0:c21b120b95fa | 25 | S4.calibrate(0.00098, 180); |
chelseamar | 0:c21b120b95fa | 26 | |
chelseamar | 0:c21b120b95fa | 27 | int motor_select; |
chelseamar | 0:c21b120b95fa | 28 | float position; |
chelseamar | 0:c21b120b95fa | 29 | wait(0.5); |
chelseamar | 0:c21b120b95fa | 30 | |
chelseamar | 0:c21b120b95fa | 31 | printf("\r\nSelect motor: "); |
chelseamar | 0:c21b120b95fa | 32 | cin >> motor_select; |
chelseamar | 0:c21b120b95fa | 33 | // motor_select -= 1; |
chelseamar | 0:c21b120b95fa | 34 | |
chelseamar | 0:c21b120b95fa | 35 | if (motor_select == 5) |
chelseamar | 0:c21b120b95fa | 36 | position = S5.read(); |
chelseamar | 0:c21b120b95fa | 37 | |
chelseamar | 0:c21b120b95fa | 38 | printf("\r\n %f", position); |
chelseamar | 0:c21b120b95fa | 39 | |
chelseamar | 0:c21b120b95fa | 40 | float pos; |
chelseamar | 0:c21b120b95fa | 41 | printf("\r\nWhere should the motor go?"); |
chelseamar | 0:c21b120b95fa | 42 | cin >> pos; |
chelseamar | 0:c21b120b95fa | 43 | S5 = pos; |
chelseamar | 0:c21b120b95fa | 44 | wait(1.0); |
chelseamar | 0:c21b120b95fa | 45 | |
chelseamar | 0:c21b120b95fa | 46 | printf("%f", S5.read()); |
chelseamar | 0:c21b120b95fa | 47 | |
chelseamar | 0:c21b120b95fa | 48 | // myservo.calibrate(0.00098, 180); |
chelseamar | 0:c21b120b95fa | 49 | // while(1) { |
chelseamar | 0:c21b120b95fa | 50 | // for(int i=0; i<100; i++) { |
chelseamar | 0:c21b120b95fa | 51 | // myservo = i/100.0; |
chelseamar | 0:c21b120b95fa | 52 | // wait(0.01); |
chelseamar | 0:c21b120b95fa | 53 | // } |
chelseamar | 0:c21b120b95fa | 54 | // |
chelseamar | 0:c21b120b95fa | 55 | // wait(2.0); |
chelseamar | 0:c21b120b95fa | 56 | // |
chelseamar | 0:c21b120b95fa | 57 | // for(int i=100; i>0; i--) { |
chelseamar | 0:c21b120b95fa | 58 | // myservo = i/100.0; |
chelseamar | 0:c21b120b95fa | 59 | // wait(0.01); |
chelseamar | 0:c21b120b95fa | 60 | // } |
chelseamar | 0:c21b120b95fa | 61 | // |
chelseamar | 0:c21b120b95fa | 62 | // wait(2.0); |
chelseamar | 0:c21b120b95fa | 63 | // } |
chelseamar | 0:c21b120b95fa | 64 | // |
chelseamar | 0:c21b120b95fa | 65 | // myservo.write(1); |
chelseamar | 0:c21b120b95fa | 66 | // wait(2.0); |
chelseamar | 0:c21b120b95fa | 67 | // myservo.write(0); |
chelseamar | 0:c21b120b95fa | 68 | // wait(2.0); |
chelseamar | 0:c21b120b95fa | 69 | } |