I have some trouble generating an array with servo objects, and does anyone think this code is fast enough?
Thanks for any comments
Kim
(Marked the error in the code)
#include <ServoTimer2.h> // the servo library
byte antallServoer = 9;
//Which pins the servo in are connected to
byte servoIn [9] = {
2,4,5,6,7,8,9,11,12};
//Which pins the servo out are connected to
byte servoOut [9] = {
3,10,14,15,16,13,17,18,19};
long startPulse = 0;
long pulseWidth = 0;
int pulsMin = 1000;
int pulsMax = 2000;
int pulsNeutral = 1500;
// Array that holds the 9 servo out objects.. Here it fails
ServoTimer2 servo[antallServoer];
void setup() {
Serial.begin(19200);
for(byte i=0;i<antallServoer ;i++){
servo[i].attach(servoOut[i]); // attach a pin to the servos
pinMode(servoIn[i], INPUT); // declare pushbutton as input
}
Serial.println("Setup Done");
}
////////////////////////////////////////////////////////////
void loop()
{
for(byte i=0;i<antallServoer ;i++){
if(digitalRead(servoIn[i])==HIGH){
startPulse = millis();
}
while(digitalRead(servoIn[i])==HIGH){
//communicate over serial
}
pulseWidth = millis()-startPulse;
if(pulseWidth >= pulsMax){
pulseWidth = pulsMax;
//write warning on serial
}
if(pulseWidth <= pulsMin){
pulseWidth = pulsMin;
//write warning on serial
}
servo[i].write(pulseWidth);
}
}