Project for 380

Dependencies:   mbed Servo

Committer:
b28nguye
Date:
Sat Sep 28 17:28:05 2019 +0000
Revision:
1:679934743c5e
Parent:
0:110dc3bbf9c1
import to Mbed Studio

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 1:679934743c5e 4 #include "stdio.h"
b28nguye 0:110dc3bbf9c1 5
b28nguye 0:110dc3bbf9c1 6 Servo servo_1(D3);
b28nguye 0:110dc3bbf9c1 7 Servo servo_2(D5);
b28nguye 0:110dc3bbf9c1 8 Servo servo_3(D6);
b28nguye 0:110dc3bbf9c1 9 Servo servo_4(D9);
b28nguye 0:110dc3bbf9c1 10 Servo servo_5(D10);
b28nguye 0:110dc3bbf9c1 11 Servo servo_6(D11);
b28nguye 0:110dc3bbf9c1 12
b28nguye 0:110dc3bbf9c1 13
b28nguye 0:110dc3bbf9c1 14 void test_write(Servo servo_ID){
b28nguye 0:110dc3bbf9c1 15 while(1) {
b28nguye 0:110dc3bbf9c1 16 wait(1.0);
b28nguye 0:110dc3bbf9c1 17
b28nguye 0:110dc3bbf9c1 18 for(int i=0; i<100; i++) { //adjust range
b28nguye 0:110dc3bbf9c1 19 servo_ID = i/100.0; //adjust speed
b28nguye 0:110dc3bbf9c1 20 wait(0.01);
b28nguye 0:110dc3bbf9c1 21 }
b28nguye 0:110dc3bbf9c1 22 wait(1.0);
b28nguye 0:110dc3bbf9c1 23
b28nguye 0:110dc3bbf9c1 24 for(int i=100; i>0; i--) {
b28nguye 0:110dc3bbf9c1 25 servo_ID = i/100.0;
b28nguye 0:110dc3bbf9c1 26 wait(0.01);
b28nguye 0:110dc3bbf9c1 27 }
b28nguye 0:110dc3bbf9c1 28 }
b28nguye 0:110dc3bbf9c1 29 }
b28nguye 0:110dc3bbf9c1 30
b28nguye 0:110dc3bbf9c1 31 void test_position(Servo servo_ID){
b28nguye 0:110dc3bbf9c1 32 int y =0;
b28nguye 0:110dc3bbf9c1 33 while(1){
b28nguye 0:110dc3bbf9c1 34 y +=1;
b28nguye 0:110dc3bbf9c1 35 printf("Test %d ", y);
b28nguye 0:110dc3bbf9c1 36 for (int i=-90; i<=90; i+=45){
b28nguye 0:110dc3bbf9c1 37 servo_ID.position(i);
b28nguye 0:110dc3bbf9c1 38 servo_2.position(i);
b28nguye 0:110dc3bbf9c1 39 //servo_3.position(i);
b28nguye 0:110dc3bbf9c1 40 wait(1);
b28nguye 0:110dc3bbf9c1 41 //printf("Angle %d", i);
b28nguye 0:110dc3bbf9c1 42 //wait(1);
b28nguye 0:110dc3bbf9c1 43 }
b28nguye 0:110dc3bbf9c1 44 }
b28nguye 0:110dc3bbf9c1 45 }
b28nguye 0:110dc3bbf9c1 46
b28nguye 0:110dc3bbf9c1 47 int main() {
b28nguye 1:679934743c5e 48 printf ("\n test start\n");
b28nguye 0:110dc3bbf9c1 49 wait(1.0);
b28nguye 0:110dc3bbf9c1 50 //test_write(servo_1);
b28nguye 1:679934743c5e 51 //test_position(servo_1);
b28nguye 0:110dc3bbf9c1 52 int x = 0;
b28nguye 1:679934743c5e 53 char n;
b28nguye 1:679934743c5e 54 int y;
b28nguye 0:110dc3bbf9c1 55 while (1){
b28nguye 1:679934743c5e 56 printf ("Test %d \n", x);
b28nguye 0:110dc3bbf9c1 57 x +=1;
b28nguye 1:679934743c5e 58 scanf("%1c", &n);
b28nguye 1:679934743c5e 59 printf("You said, %c \n", n);
b28nguye 0:110dc3bbf9c1 60 }
b28nguye 0:110dc3bbf9c1 61 }