Hi, I ran into another issue in the same project.
I got the first 16 (we changed it from 18 to 16) servos to work with no problem, however the other 16 servos are not working the way they should, they just kind of wobble a bit randomly and I can't figure what seems to be the problem.
They are supposed to sweep from 30 degrees to 160 degrees if I give them a "1" and just stop if I give them a "0", but either just shaking a bit at random times or just flat out not move at all.
Any suggestions are very much appreciated.
Here is the code I have so far.
#include <Servo.h>
//________________________________
//----------------------- cat data
const int catNum = 16;
int minHandPos = 30;
int maxHandPos = 160;
int shakeSpeed = 10;
//================================
//________________________________
//--------------------- servo data
Servo assServo[catNum];
Servo handServo[catNum];
int assServoPin[catNum] = {3, 6, 9, 12, 22, 26, 28, 32, 34, 38, 40, 44, 46, 50, 52, A0};
int handServoPin[catNum] = {4, 7, 10, 13, 23, 27, 29, 33, 35, 39, 41, 45, 47, 51, 53, A1};
boolean shakeBool[catNum];
int assPos[catNum];
int handPos[catNum];
int servoCount = 0;
//================================
// FUNCTION_________________________________________
//--------------------------------------------------
void setup(){
Serial.begin(115200);
// set ass servo
for(int i=0; i<catNum; i++){
assServo[i].attach(assServoPin[i]);
handServo[i].attach(handServoPin[i]);
assPos[i] = 90;
assServo[i].write(assPos[i]);
handPos[i] = minHandPos;
handServo[i].write(handPos[i]);
shakeBool[i] = false;
}
}
void loop(){
if(Serial.available()){
uint8_t v = Serial.read();
if(v == 255){ //Marker for next loop
servoCount = 0;
}else{
if(servoCount<catNum){
assServo[servoCount].write(v);
servoCount++;
}
else
{
for(int i=0; i<8; i++){
if(bitRead(v, i) == 1){ // "ON"
if(handPos[(servoCount-catNum)] <= minHandPos){
shakeBool[(servoCount-catNum)] = true;
// If it is under the minimum angle
}
else if(handPos[(servoCount-catNum)]>=maxHandPos){
shakeBool[(servoCount-catNum)] = false;
//If it is over the maximum angle
}
if(shakeBool[(servoCount-catNum)]){
handPos[(servoCount-catNum)]+=shakeSpeed;
handServo[(servoCount-catNum)].write(handPos[(servoCount-catNum)]);
// +angle and send to servo
}else{
handPos[(servoCount-catNum)]-=shakeSpeed;
handServo[(servoCount-catNum)].write(handPos[(servoCount-catNum)]);
// - angle and send to servo
}
delay(30);
}else{ // "OFF"
//Do nothing
}
servoCount++;
}
}
}
if(servoCount >= ((catNum*2)-1)) servoCount = 0;
}
}