Bat Ear Code
/
multiServoBat
a program
Fork of multiServoBat by
Diff: main.cpp
- Revision:
- 4:5bf4d3c6ec3b
- Parent:
- 3:88de581de68d
- Child:
- 5:90f7d451910e
--- a/main.cpp Fri Aug 02 14:50:14 2019 +0000 +++ b/main.cpp Tue Aug 06 15:50:39 2019 +0000 @@ -6,83 +6,85 @@ float range = 0.0005; float degrees = 45.0; -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 - +void bothForwardOrBack(float min, float max, int direction, int startVEnd); //1 is forward, 2 is backwards +void oneSideForwardOrBack(float min, float max, int direction, int side, int startVEnd);//1 is forward 2 is back, 1 is left 0 is right +void movementCombo(float randoNum, int forwardVBack); int main() { - printf("Hello bats!\n"); - - printf("entering loop\n"); while(1) { - printf("entering together() call\n"); - - //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); + int rando = rand(); + // float randoNum = rando/32767; + float randoNum = 0.56; + movementCombo(randoNum, 1); + wait(3); + movementCombo(randoNum, 2); + wait(3); } } -void bothForwardOrBack(int direction) +void bothForwardOrBack(float min, float max, int direction, int startVEnd) { + //1 is forward 2 is backwards float minServo, maxServo; if (direction == 1) { minServo = NUM_SERVOS/2; maxServo = NUM_SERVOS; } - if (direction == 2) + else 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) + + float incr = 0.01; + if(startVEnd == 0) { - for(j = minServo; j<maxServo; j++) + for(i = min; i<max; i+=incr) { - servo[j] = i; + for(j = minServo; j<maxServo; j++) + { + servo[j] = i; + } + wait(0.005); } - wait(0.005); } - wait(0.25); - for(i = max; i>min; i-=incr) + else if(startVEnd == 1) { - for(j = minServo; j<maxServo; j++) + for(i = max; i>min; i-=incr) { - servo[j] = i; + for(j = minServo; j<maxServo; j++) + { + servo[j] = i; + } + wait(0.005); } - wait(0.005); } - wait(0.25); printf("finished one run of bothForwardOrBack\n"); } -void oneSideForwardOrBack(int direction, int side) +void movementCombo(float randoNum, int forwardVBack) +{ + //forward is 1, back is 2 + + bothForwardOrBack(0.0, randoNum, forwardVBack, 0); //moves both ears partway + wait(1); + oneSideForwardOrBack(randoNum, 1.0, forwardVBack, 1, 0); //moves left ear rest of way + oneSideForwardOrBack(randoNum, 1.0, forwardVBack, 1, 1); //moves left ear back to position + + oneSideForwardOrBack(randoNum, 1.0, forwardVBack, 0, 0); //moves right ear rest of way + oneSideForwardOrBack(randoNum, 1.0, forwardVBack, 0, 1); //moves right ear back to position + wait(1); + bothForwardOrBack(0.0, randoNum, forwardVBack, 1); //moves both ears to position 0 + + wait(1); +} +void oneSideForwardOrBack(float min, float max, int direction, int side, int startVEnd) { //direction: one is forwards two is backwards + //0 is right, 1 is left int whichServo = 0; - if(direction == 2) + if(direction == 1) { whichServo = whichServo + NUM_SERVOS/2; } @@ -90,20 +92,25 @@ { whichServo = whichServo + 1; } - - float max = 1.0, min = 0.0, incr = 0.01; - float i; - for(i = min; i<max; i+=incr) + + float incr = 0.01, i; + if(startVEnd == 0) { - servo[whichServo] = i; - wait(0.005); + for(i = min; i<max; i+=incr) + { + servo[whichServo] = i; + wait(0.002); + } + wait(0.1); } - wait(0.25); - for(i = max; i>min; i-=incr) + else if(startVEnd == 1) { - servo[whichServo] = i; - wait(0.005); + for(i = max; i>min; i-=incr) + { + servo[whichServo] = i; + wait(0.002); + } + wait(0.1); } - wait(0.25); printf("finished one run of oneSideForwardOrBack\n"); } \ No newline at end of file