Project for 380

Dependencies:   mbed Servo

Committer:
b28nguye
Date:
Fri Sep 27 15:21:03 2019 +0000
Revision:
0:110dc3bbf9c1
Child:
1:679934743c5e
sure;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
b28nguye 0:110dc3bbf9c1 1 // Continuously sweep the servo through it's full range
b28nguye 0:110dc3bbf9c1 2 #include "mbed.h"
b28nguye 0:110dc3bbf9c1 3 #include "Servo.h"
b28nguye 0:110dc3bbf9c1 4
b28nguye 0:110dc3bbf9c1 5 Servo servo_1(D3);
b28nguye 0:110dc3bbf9c1 6 Servo servo_2(D5);
b28nguye 0:110dc3bbf9c1 7 Servo servo_3(D6);
b28nguye 0:110dc3bbf9c1 8 Servo servo_4(D9);
b28nguye 0:110dc3bbf9c1 9 Servo servo_5(D10);
b28nguye 0:110dc3bbf9c1 10 Servo servo_6(D11);
b28nguye 0:110dc3bbf9c1 11
b28nguye 0:110dc3bbf9c1 12
b28nguye 0:110dc3bbf9c1 13 void test_write(Servo servo_ID){
b28nguye 0:110dc3bbf9c1 14 while(1) {
b28nguye 0:110dc3bbf9c1 15 wait(1.0);
b28nguye 0:110dc3bbf9c1 16
b28nguye 0:110dc3bbf9c1 17 for(int i=0; i<100; i++) { //adjust range
b28nguye 0:110dc3bbf9c1 18 servo_ID = i/100.0; //adjust speed
b28nguye 0:110dc3bbf9c1 19 wait(0.01);
b28nguye 0:110dc3bbf9c1 20 }
b28nguye 0:110dc3bbf9c1 21 wait(1.0);
b28nguye 0:110dc3bbf9c1 22
b28nguye 0:110dc3bbf9c1 23 for(int i=100; i>0; i--) {
b28nguye 0:110dc3bbf9c1 24 servo_ID = i/100.0;
b28nguye 0:110dc3bbf9c1 25 wait(0.01);
b28nguye 0:110dc3bbf9c1 26 }
b28nguye 0:110dc3bbf9c1 27 }
b28nguye 0:110dc3bbf9c1 28 }
b28nguye 0:110dc3bbf9c1 29
b28nguye 0:110dc3bbf9c1 30 void test_position(Servo servo_ID){
b28nguye 0:110dc3bbf9c1 31 int y =0;
b28nguye 0:110dc3bbf9c1 32 while(1){
b28nguye 0:110dc3bbf9c1 33 y +=1;
b28nguye 0:110dc3bbf9c1 34 printf("Test %d ", y);
b28nguye 0:110dc3bbf9c1 35 for (int i=-90; i<=90; i+=45){
b28nguye 0:110dc3bbf9c1 36 servo_ID.position(i);
b28nguye 0:110dc3bbf9c1 37 servo_2.position(i);
b28nguye 0:110dc3bbf9c1 38 //servo_3.position(i);
b28nguye 0:110dc3bbf9c1 39 wait(1);
b28nguye 0:110dc3bbf9c1 40 //printf("Angle %d", i);
b28nguye 0:110dc3bbf9c1 41 //wait(1);
b28nguye 0:110dc3bbf9c1 42 }
b28nguye 0:110dc3bbf9c1 43 }
b28nguye 0:110dc3bbf9c1 44 }
b28nguye 0:110dc3bbf9c1 45
b28nguye 0:110dc3bbf9c1 46 int main() {
b28nguye 0:110dc3bbf9c1 47 printf ("test start");
b28nguye 0:110dc3bbf9c1 48 wait(1.0);
b28nguye 0:110dc3bbf9c1 49 //test_write(servo_1);
b28nguye 0:110dc3bbf9c1 50 test_position(servo_1);
b28nguye 0:110dc3bbf9c1 51 int x = 0;
b28nguye 0:110dc3bbf9c1 52 while (1){
b28nguye 0:110dc3bbf9c1 53 printf ("Test %d ", x);
b28nguye 0:110dc3bbf9c1 54 x +=1;
b28nguye 0:110dc3bbf9c1 55 }
b28nguye 0:110dc3bbf9c1 56 }