Bat Ear Code
/
multiServoBat
a program
Fork of multiServoBat by
Diff: main.cpp
- Revision:
- 3:88de581de68d
- Parent:
- 2:7e5d670ed9aa
- Child:
- 4:5bf4d3c6ec3b
--- a/main.cpp Thu Aug 01 14:40:15 2019 +0000 +++ b/main.cpp Fri Aug 02 14:50:14 2019 +0000 @@ -6,8 +6,8 @@ float range = 0.0005; float degrees = 45.0; -void together(); -void apart(int side); +void bothForwardOrBack(int direction); //1 is forward, 2 is backwards +void oneSideForwardOrBack(int direction, int side);//1 is forward 2 is back, 1 is left 0 is right int main() { printf("Hello bats!\n"); @@ -15,74 +15,95 @@ printf("entering loop\n"); while(1) { printf("entering together() call\n"); - together(); - wait(5); - apart(0); - wait(2); - apart(1); - wait(2); + + //move both ears forward + bothForwardOrBack(1); + wait(1); + //move both ears backward + bothForwardOrBack(2); + wait(1); + + //LEFT EAR + //move left ear back + oneSideForwardOrBack(1,1); + wait(1); + //move left ear forward + oneSideForwardOrBack(2,1); + wait(1); + + //RIGHT EAR + //move right ear back + oneSideForwardOrBack(1,0); + wait(1); + //move right ear forward + oneSideForwardOrBack(2,0); + wait(1); } } - -void together() +void bothForwardOrBack(int direction) { + float minServo, maxServo; + if (direction == 1) + { + minServo = NUM_SERVOS/2; + maxServo = NUM_SERVOS; + } + if (direction == 2) + { + minServo = 0; + maxServo = NUM_SERVOS/2; + } float i; int j; float max = 1.0, min = 0.0, incr = 0.01; for(i = min; i<max; i+=incr) { - for(j = 0; j<NUM_SERVOS; j++) + for(j = minServo; j<maxServo; j++) { servo[j] = i; } - wait(0.01); + wait(0.005); } - wait(1); + wait(0.25); for(i = max; i>min; i-=incr) { - for(j = 0; j<NUM_SERVOS; j++) + for(j = minServo; j<maxServo; j++) { servo[j] = i; } - wait(0.01); + wait(0.005); } - wait(1); - printf("finished one of together\n"); + wait(0.25); + printf("finished one run of bothForwardOrBack\n"); } - -//only moves two of the servo motors, which 2 depends on the parameter side: runs 1 and 3 when side = 1, runs 2 and 4 when side = 0 -void apart (int side) +void oneSideForwardOrBack(int direction, int side) { + //direction: one is forwards two is backwards + int whichServo = 0; + if(direction == 2) + { + whichServo = whichServo + NUM_SERVOS/2; + } + if(side == 1) + { + whichServo = whichServo + 1; + } + + float max = 1.0, min = 0.0, incr = 0.01; float i; - int j; - float max = 1.0, min = 0.0, incr = 0.01; for(i = min; i<max; i+=incr) { - for(j = 0; j<NUM_SERVOS; j++) - { - if(j%2 == side) - { - servo[j] = i; - } - - - } - wait(0.01); + servo[whichServo] = i; + wait(0.005); } - wait(1); + wait(0.25); for(i = max; i>min; i-=incr) { - for(j = 0; j<NUM_SERVOS; j++) - { - if(j%2 == side) - { - servo[j] = i; - } - } - wait(0.01); + servo[whichServo] = i; + wait(0.005); } - wait(1); - printf("finished one of together\n"); + wait(0.25); + printf("finished one run of oneSideForwardOrBack\n"); } \ No newline at end of file