Hey,
I was hoping someone might be able to help me. I am using an SSC-32 (the old style with the serial port) and an Arduino Nano.
I am trying to control all 32 servos and have them activated by a sensor.
The code runs fine for a couple of minutes but after that the QP seems to go out of sync somehow. I am not much of a coder but I think the code is OK.
The code is below:
[code]class Sensor {
private: byte anaPin;
public: int triggerValue;
public: Sensor(byte anaPin_) {
anaPin = anaPin_;
}
int query(){
return analogRead(anaPin);//reading;
}
};
class Flower{
private: int sscPin, startTime;
public: byte posit;
public: boolean isMoving;
public: Flower(byte sscPin_){
sscPin = sscPin_;
}
byte query(){
Serial.print(“QP”);
Serial.println(sscPin);
startTime = millis();
do {} while ((Serial.available() == 0) && millis() - startTime <1000);
posit = Serial.read();
}
Serial.print(" PULSE pulse ");
Serial.println(posit);
//delay(20);
return posit;
}
void move(int targetPosition, int targetTime){
Serial.print("#");
Serial.print(sscPin);
Serial.print(“P”);
Serial.print(targetPosition);
Serial.print(“T”);
Serial.println(targetTime);
isMoving = true;
//delay(50);
}
void moving(boolean state){
isMoving = state;
}
};
// START MAIN //
static const int openPos = 1270;
static const int closedPos = 2250;
Sensor *sensors[8];
Flower *flowers[32];
int timer, frameTime, triggerValue, count, flowerIndex, seedNumber, tolerance;
byte pulse;
boolean mov;
void setup() {
Serial.begin(9600);
triggerValue = 150;
tolerance = 1;
count = 0;
for (int i = 0; i < 8; i++) {
sensors = new Sensor(i);
}
for (int i = 0; i < 32; i++) {
flowers = new Flower(i);
}
Serial.println(“Set Up”);
for (int i = 0; i <32; i++){
flowers -> move(openPos, 1000);
//delay(200);
}
}
void loop() {
for (int i = 0; i < 1; i++){
if (sensors -> query() > triggerValue) {
//seedNumber = ceil(random(4)) + i*4;
//seedNumber = 2;
flowerIndex = ceil(random(4));//seedNumber + 2 * ( ( round((seedNumber%/2)+1 ) %3 -1);
pulse = flowers[flowerIndex] -> query();
// mov = flowers[flowerIndex] -> isMoving;
if (pulse >= closedPos/10){
flowers[flowerIndex] -> move(openPos,500);
}
}
}
pulse = flowers[count] -> query();
if(pulse >= closedPos/10 || pulse <= openPos){
flowers[count] -> moving(false);
}
if ( pulse <= openPos/10 ){
mov = flowers[count] -> isMoving;
if (!mov){
flowers[count] -> move(closedPos,650);// snap back
}
}
count = (count + 1) % 4;//2;
}
[/code]****
Any help would be gratefully received.****