Hello everybody. I have just written this program. Don't mind the annotation, they're in french and I don't think they have much importance :). So this program controls 6 servos. To make things a bit more organized, I have created a .h file (header) where I put the prototype of the functions and a .cpp in which I define them. However, when I try to compile it, I just get a message error which says :"Error compiling". Here are the files :
the main one :
#include "Servo_command.h"
#include <Servo.h>
#include "Arduino.h"
Servo myservo1, myservo2, myservo3, myservo4, myservo5, myservo6;
int pos = 0;
int pos_max = 90;
int pos_min = 56; // position la plus basse du servo
int ND = 4; // Nombre de notes différentes
int SRT = (pos_max-pos_min)*10*2; // temps que met le servo pour monter puis redescendre
int k = 0;
int l = 0;
void setup()
{
myservo1.attach(7);
myservo2.attach(8);
myservo3.attach(9);
myservo4.attach(10);
myservo5.attach(11);
myservo6.attach(12);
}
void loop()
{
toutMonter();
toutDescendre();
k = k+1;
l = (k % ND) +1; // A chaque fois que le servo atteindra cette position, une valeur "l" sera stocké, allant de 1 à ND : il représente à chaque itération les notes les unes à la suite des autres.
if ( l == 1 || l == 2 ) {delay(1000-SRT);} // Si la valeur de "l" est de 1 ou 2, le servo reste en bas pendant 1000-SRT(=le temps que met le servo pour son aller-retout) ms.
if ( l == 3 || l == 4 ) {delay(2000-SRT);} // Si la valeur de "l" est de 3 ou 4, le servo reste en bas pendant 2000-SRT(=le temps que met le servo pour son aller-retout) ms.
}
The .cpp :
#include "Servo_command.h"
#include <Servo.h>
#include "Arduino.h"
Servo myservo1, myservo2, myservo3, myservo4, myservo5, myservo6;
int pos = 0;
int pos_max = 90;
int pos_min = 56; // position la plus basse du servo
int ND = 4; // Nombre de notes différentes
int SRT = (pos_max-pos_min)*10*2; // temps que met le servo pour monter puis redescendre
int k = 0;
int l = 0;
void monter1(Servo myservo1)
{
for (pos = pos_min; pos <= pos_max; pos++)
{
myservo1.write(pos);
delay(10);
}
}
void monter2(Servo myservo1, Servo myservo2)
{
for (pos = pos_min; pos <= pos_max; pos++)
{
myservo1.write(pos);
myservo2.write(pos);
delay(10);
}
}
void monter3(Servo myservo1, Servo myservo2, Servo myservo3)
{
for (pos = pos_min; pos <= pos_max; pos++)
{
myservo1.write(pos);
myservo2.write(pos);
myservo3.write(pos);
delay(10);
}
}
void monter4(Servo myservo1, Servo myservo2, Servo myservo3, Servo myservo4)
{
for (pos = pos_min; pos <= pos_max; pos++)
{
myservo1.write(pos);
myservo2.write(pos);
myservo3.write(pos);
myservo4.write(pos);
delay(10);
}
}
void monter5(Servo myservo1, Servo myservo2, Servo myservo3, Servo myservo4, Servo myservo5)
{
for (pos = pos_min; pos <= pos_max; pos++)
{
myservo1.write(pos);
myservo2.write(pos);
myservo3.write(pos);
myservo4.write(pos);
myservo5.write(pos);
delay(10);
}
}
void toutMonter()
{
for (pos = pos_min; pos <= pos_max; pos++)
{
myservo1.write(pos);
myservo2.write(pos);
myservo3.write(pos);
myservo4.write(pos);
myservo5.write(pos);
myservo6.write(pos);
delay(10);
}
}
void descendre1(Servo myservo1)
{
for (pos = pos_max; pos >= pos_min; pos--)
{
myservo1.write(pos);
delay(10);
}
}
void descendre2(Servo myservo1, Servo myservo2)
{
for (pos = pos_max; pos >= pos_min; pos--)
{
myservo1.write(pos);
myservo2.write(pos);
delay(10);
}
}
void descendre3(Servo myservo1, Servo myservo2, Servo myservo3)
{
for (pos = pos_max; pos >= pos_min; pos--)
{
myservo1.write(pos);
myservo2.write(pos);
myservo3.write(pos);
delay(10);
}
}
void descendre4(Servo myservo1, Servo myservo2, Servo myservo3, Servo myservo4)
{
for (pos = pos_max; pos >= pos_min; pos--)
{
myservo1.write(pos);
myservo2.write(pos);
myservo3.write(pos);
myservo4.write(pos);
delay(10);
}
}
void descendre5(Servo myservo1, Servo myservo2, Servo myservo3, Servo myservo4, Servo myservo5)
{
for (pos = pos_max; pos >= pos_min; pos--)
{
myservo1.write(pos);
myservo2.write(pos);
myservo3.write(pos);
myservo4.write(pos);
myservo5.write(pos);
delay(10);
}
}
void toutDescendre()
{
for (pos = pos_max; pos >= pos_min; pos--)
{
myservo1.write(pos);
myservo2.write(pos);
myservo3.write(pos);
myservo4.write(pos);
myservo5.write(pos);
myservo6.write(pos);
delay(10);
}
}
And finally the .h :
#ifndef Servo_command.h
#define Servo_command.h
#include "Arduino.h"
#include <Servo.h>
void monter1(Servo myservo1);
void monter2(Servo myservo1, Servo myservo2);
void monter3(Servo myservo1, Servo myservo2, Servo myservo3);
void monter4(Servo myservo1, Servo myservo2, Servo myservo3, Servo myservo4);
void monter5(Servo myservo1, Servo myservo2, Servo myservo3, Servo myservo4, Servo myservo5);
void toutMonter();
void descendre1(Servo myservo1);
void descendre2(Servo myservo1, Servo myservo2);
void descendre3(Servo myservo1, Servo myservo2, Servo myservo3);
void descendre4(Servo myservo1, Servo myservo2, Servo myservo3, Servo myservo4);
void descendre5(Servo myservo1, Servo myservo2, Servo myservo3, Servo myservo4, Servo myservo5);
void toutDescendre();
#endif
Any help is welcomed !