Hello les makers.
J'aurais besoin d'un peu d'aide sur une structure que voici :
class Sweeper
{
Servo servo; // the servo
int pos; // current servo position
int increment; // increment to move for each interval
int updateInterval; // interval between updates
unsigned long lastUpdate; // last update of position
public:
Sweeper(int interval)
{
updateInterval = interval;
increment = 1;
}
void Attach(int pin)
{
servo.attach(pin);
}
void Detach()
{
servo.detach();
}
void Update(unsigned long currentMillis)
{
if((currentMillis - lastUpdate) > updateInterval) // time to update
{
lastUpdate = millis();
pos += increment;
servo.write(pos);
if ((pos >= 180) || (pos <= 0)) // end of sweep
{
// reverse direction
increment = -increment;
}
}
}
};
Sweeper sweeper1(25);
Sweeper sweeper2(35);
void setup()
{
sweeper1.Attach(9);
sweeper2.Attach(10);
// Timer0 is already used for millis() - we'll just interrupt somewhere
// in the middle and call the "Compare A" function below
OCR0A = 0xAF;
TIMSK0 |= _BV(OCIE0A);
}
// Interrupt is called once a millisecond, looks for any new GPS data, and stores it
SIGNAL(TIMER0_COMPA_vect)
{
unsigned long currentMillis = millis();
sweeper1.Update(currentMillis);
int
if(digitalRead(2) == HIGH)
{
sweeper2.Update(currentMillis);
}
}
void loop()
{
}
Vous remarquerez que lorsque nous avons plusieurs servomoteurs il faut leur donner la base de temps entre deux pas :
Sweeper sweeper1(25); Sweeper sweeper2(35);
Et les attacher, c'est à dire leur attribuer une broche :
sweeper1.Attach(9); sweeper2.Attach(10);
Mon problème c'est que lorsque nous avons 10/15 servomoteurs nous n'allons quand même pas écrire 10/15 ligne pour attribuer le temps de base pour chaque servomoteur et écrire 10/15 lignes pour attribuer à chaque servomoteur sa broche !!
Je pensais donc , pour 10 servomoteurs, faire une boucle du style :
for (a=0; a<=9;a++)
{
Sweeper "sweeper" + a.Attach(a+9);
{
Mais voilà !! ça marche pas !!
Une idée?
Merci par avance.
++














