Dependencies:   mbed Servo

Fork of multiServoBat by Angeline Luther

Committer:
aluthe3099
Date:
Wed Jul 31 19:13:17 2019 +0000
Revision:
0:afc37ce56e1f
Child:
1:829cbbaeaf32
7/31/2019 only moves servo once

Who changed what in which revision?

UserRevisionLine numberNew contents of line
aluthe3099 0:afc37ce56e1f 1 #include "mbed.h"
aluthe3099 0:afc37ce56e1f 2 #include "Servo.h"
aluthe3099 0:afc37ce56e1f 3 DigitalOut myled(LED2), myled2(LED1), led3(LED3);
aluthe3099 0:afc37ce56e1f 4 Servo servo1(p24), servo2(p23), servo3(p22), servo4(p21);
aluthe3099 0:afc37ce56e1f 5 int numServos = 4;
aluthe3099 0:afc37ce56e1f 6 float range = 0.0005;
aluthe3099 0:afc37ce56e1f 7 float degrees = 45.0;
aluthe3099 0:afc37ce56e1f 8
aluthe3099 0:afc37ce56e1f 9 void together(Servo * servoPtr)
aluthe3099 0:afc37ce56e1f 10 {
aluthe3099 0:afc37ce56e1f 11 int i,j;
aluthe3099 0:afc37ce56e1f 12 for(i = 0.0; i<1.00; i+=0.01)
aluthe3099 0:afc37ce56e1f 13 {
aluthe3099 0:afc37ce56e1f 14 for(j = 0; j<numServos; j++)
aluthe3099 0:afc37ce56e1f 15 {
aluthe3099 0:afc37ce56e1f 16 servoPtr[j] = i;
aluthe3099 0:afc37ce56e1f 17 }
aluthe3099 0:afc37ce56e1f 18 wait(0.01);
aluthe3099 0:afc37ce56e1f 19 }
aluthe3099 0:afc37ce56e1f 20 wait(5);
aluthe3099 0:afc37ce56e1f 21 for(i = 1.0; i>0.00; i-=0.01)
aluthe3099 0:afc37ce56e1f 22 {
aluthe3099 0:afc37ce56e1f 23 for(j = 0; j<numServos; j++)
aluthe3099 0:afc37ce56e1f 24 {
aluthe3099 0:afc37ce56e1f 25 servoPtr[j] = i;
aluthe3099 0:afc37ce56e1f 26 }
aluthe3099 0:afc37ce56e1f 27 wait(0.01);
aluthe3099 0:afc37ce56e1f 28 }
aluthe3099 0:afc37ce56e1f 29 printf("finished one of together\n");
aluthe3099 0:afc37ce56e1f 30 }
aluthe3099 0:afc37ce56e1f 31
aluthe3099 0:afc37ce56e1f 32 void apart1 (Servo * servoPtr)
aluthe3099 0:afc37ce56e1f 33 {
aluthe3099 0:afc37ce56e1f 34 int i,j;
aluthe3099 0:afc37ce56e1f 35 for(i = 0.0; i<1.00; i+=0.01)
aluthe3099 0:afc37ce56e1f 36 {
aluthe3099 0:afc37ce56e1f 37 for(j = 0; j<numServos; j++)
aluthe3099 0:afc37ce56e1f 38 {
aluthe3099 0:afc37ce56e1f 39 if(j%1 == 0)
aluthe3099 0:afc37ce56e1f 40 {
aluthe3099 0:afc37ce56e1f 41 servoPtr[j] = i;
aluthe3099 0:afc37ce56e1f 42 }
aluthe3099 0:afc37ce56e1f 43
aluthe3099 0:afc37ce56e1f 44
aluthe3099 0:afc37ce56e1f 45 }
aluthe3099 0:afc37ce56e1f 46 wait(0.01);
aluthe3099 0:afc37ce56e1f 47 }
aluthe3099 0:afc37ce56e1f 48 wait(5);
aluthe3099 0:afc37ce56e1f 49 for(i = 1.0; i>0.00; i-=0.01)
aluthe3099 0:afc37ce56e1f 50 {
aluthe3099 0:afc37ce56e1f 51 if(j%1 == 0)
aluthe3099 0:afc37ce56e1f 52 {
aluthe3099 0:afc37ce56e1f 53 servoPtr[j] = i;
aluthe3099 0:afc37ce56e1f 54 }
aluthe3099 0:afc37ce56e1f 55
aluthe3099 0:afc37ce56e1f 56 wait(0.01);
aluthe3099 0:afc37ce56e1f 57 }
aluthe3099 0:afc37ce56e1f 58 printf("finished one of together\n");
aluthe3099 0:afc37ce56e1f 59 }
aluthe3099 0:afc37ce56e1f 60
aluthe3099 0:afc37ce56e1f 61 int main() {
aluthe3099 0:afc37ce56e1f 62 myled = 1;
aluthe3099 0:afc37ce56e1f 63 wait(2);
aluthe3099 0:afc37ce56e1f 64 myled = 0;
aluthe3099 0:afc37ce56e1f 65 myled2 = 1;
aluthe3099 0:afc37ce56e1f 66 wait(2);
aluthe3099 0:afc37ce56e1f 67 myled2 = 0;
aluthe3099 0:afc37ce56e1f 68 led3 = 1;
aluthe3099 0:afc37ce56e1f 69 wait(2);
aluthe3099 0:afc37ce56e1f 70 led3 = 0;
aluthe3099 0:afc37ce56e1f 71
aluthe3099 0:afc37ce56e1f 72 Servo servoArr [] = {servo1, servo2, servo3, servo4};
aluthe3099 0:afc37ce56e1f 73 Servo *servoPtr;
aluthe3099 0:afc37ce56e1f 74 int x;
aluthe3099 0:afc37ce56e1f 75 //for(x = 0; x<numServos; x++)
aluthe3099 0:afc37ce56e1f 76 // {
aluthe3099 0:afc37ce56e1f 77 // myled = 1;
aluthe3099 0:afc37ce56e1f 78 // servoArr[x].calibrate(range, degrees);
aluthe3099 0:afc37ce56e1f 79 // }
aluthe3099 0:afc37ce56e1f 80 myled = 0;
aluthe3099 0:afc37ce56e1f 81 myled2 = 0;
aluthe3099 0:afc37ce56e1f 82 servoPtr = servoArr;
aluthe3099 0:afc37ce56e1f 83 //while(1) {
aluthe3099 0:afc37ce56e1f 84 for(x = 0; x<10; x++){
aluthe3099 0:afc37ce56e1f 85 myled = 0;
aluthe3099 0:afc37ce56e1f 86 myled2 = 1;
aluthe3099 0:afc37ce56e1f 87 wait(2);
aluthe3099 0:afc37ce56e1f 88
aluthe3099 0:afc37ce56e1f 89 int i,j;
aluthe3099 0:afc37ce56e1f 90 for(i = 0.0; i<1.00; i+=0.01)
aluthe3099 0:afc37ce56e1f 91 {
aluthe3099 0:afc37ce56e1f 92 for(j = 0; j<numServos; j++)
aluthe3099 0:afc37ce56e1f 93 {
aluthe3099 0:afc37ce56e1f 94 servoPtr[j] = i;
aluthe3099 0:afc37ce56e1f 95 }
aluthe3099 0:afc37ce56e1f 96 wait(0.01);
aluthe3099 0:afc37ce56e1f 97 }
aluthe3099 0:afc37ce56e1f 98 myled = 1;
aluthe3099 0:afc37ce56e1f 99 myled2 = 0;
aluthe3099 0:afc37ce56e1f 100 wait(5);
aluthe3099 0:afc37ce56e1f 101 for(i = 1.0; i>0.00; i-=0.01)
aluthe3099 0:afc37ce56e1f 102 {
aluthe3099 0:afc37ce56e1f 103 for(j = 0; j<numServos; j++)
aluthe3099 0:afc37ce56e1f 104 {
aluthe3099 0:afc37ce56e1f 105 servoPtr[j] = i;
aluthe3099 0:afc37ce56e1f 106 }
aluthe3099 0:afc37ce56e1f 107 wait(0.01);
aluthe3099 0:afc37ce56e1f 108 }
aluthe3099 0:afc37ce56e1f 109 wait(5);
aluthe3099 0:afc37ce56e1f 110
aluthe3099 0:afc37ce56e1f 111
aluthe3099 0:afc37ce56e1f 112
aluthe3099 0:afc37ce56e1f 113 myled = 0;
aluthe3099 0:afc37ce56e1f 114 myled2 = 1;
aluthe3099 0:afc37ce56e1f 115
aluthe3099 0:afc37ce56e1f 116 wait(2);
aluthe3099 0:afc37ce56e1f 117 for(i = 0.0; i<1.0; i+=0.01)
aluthe3099 0:afc37ce56e1f 118 {
aluthe3099 0:afc37ce56e1f 119 servoPtr[1] = i;
aluthe3099 0:afc37ce56e1f 120 wait(0.01);
aluthe3099 0:afc37ce56e1f 121 }
aluthe3099 0:afc37ce56e1f 122 wait(2);
aluthe3099 0:afc37ce56e1f 123 for(i = 1.0; i>0.0; i-=0.01)
aluthe3099 0:afc37ce56e1f 124 {
aluthe3099 0:afc37ce56e1f 125 servoPtr[1] = i;
aluthe3099 0:afc37ce56e1f 126 wait(0.01);
aluthe3099 0:afc37ce56e1f 127 }
aluthe3099 0:afc37ce56e1f 128 wait(4);
aluthe3099 0:afc37ce56e1f 129
aluthe3099 0:afc37ce56e1f 130 //together(servoPtr);
aluthe3099 0:afc37ce56e1f 131 //wait(10);
aluthe3099 0:afc37ce56e1f 132 //apart1(servoPtr);
aluthe3099 0:afc37ce56e1f 133 }
aluthe3099 0:afc37ce56e1f 134
aluthe3099 0:afc37ce56e1f 135 }