fabpolli:
Ciao, se non ho capito male il tuo problema si riduce alla sola creazione di altre quattro variabili (o meglio sarebbe fare dello costanti) per indicare a che pin hai collegato gli altri motori, poi con delle strutture condizionali (if, switch) che più ritieni opportune piloti il motore che desideri. Ad esempio
Allora ho creato le variabili nominando i motori
// init motorino
int DIR_PIN_M1 =7;
int STEP_PIN_M1 =5;
int SLEEP = 6; // PIN 12 = SLP
int DIR_PIN_M2 =2;
int STEP_PIN_M2 =3;
e fin quì va tutto bene
int shutter_on = 200; //tempo di pressione per attivare la cam, da settare intorno i 100 e 300
int shutter_off = 1500; // tempo di attesa prima di attivare il motorino
int wakeup = 1000; //Tempo fuoco acceso
int wakewait =200; //time between wake and shutter
int outpin = 13; //uscita per lo scatto
int wakepin = 12; //uscita per la messa a fuoco
// init motorino
int DIR_PIN_M1 =7;
int STEP_PIN_M1 =5;
int SLEEP = 6; // PIN 12 = SLP
int DIR_PIN_M2 =2;
int STEP_PIN_M2 =3;
int delayTime = 500;
void setup() {
// init dei pin per lo scatto
pinMode(outpin, OUTPUT); //outpin gives output
pinMode(wakepin, OUTPUT); //wakepin gives output
// Tempo scatto Otturatore
shutter_on = 4000;
// init dei pin per il motorino
pinMode(DIR_PIN_M1, OUTPUT);
pinMode(STEP_PIN_M1, OUTPUT);
pinMode(SLEEP, OUTPUT); // set pin 12 to output
pinMode(DIR_PIN_M2, OUTPUT);
pinMode(STEP_PIN_M2, OUTPUT);
}
/////////// Loop ////////////
void loop(){
digitalWrite(wakepin, HIGH); //turn wakeup/focus on
delay(wakeup); //keep focus
digitalWrite(wakepin, LOW); //turn wakeup off
delay(wakewait); //wait
digitalWrite(outpin, HIGH); //press the shutter
delay(shutter_on); //wait the shutter release time
digitalWrite(outpin, LOW); //release shutter
delay(shutter_off); //wait for next round
//rotate a specific number of microsteps (8 microsteps per step)
//Avanti a 200 step
digitalWrite(SLEEP, HIGH); // Sveglia il motore.
rotate_M1(4000, 0.5);
digitalWrite(SLEEP, LOW); // Spegne il motore
delay(2000);
}
void rotate_M1(int steps, float speed){
//rotate a specific number of microsteps (8 microsteps per step) - (negitive for reverse movement)
//speed is any number from .01 -> 1 with 1 being fastest - Slower is stronger
int dir = (steps > 0)? HIGH:LOW;
steps = abs(steps);
digitalWrite(DIR_PIN_M1,dir);
float usDelay = (1/speed) * 70;
for(int i=0; i < steps; i++){
digitalWrite(STEP_PIN_M1, HIGH);
delayMicroseconds(usDelay);
digitalWrite(STEP_PIN_M1, LOW);
delayMicroseconds(usDelay);
}
}
Però se inserisco una void rotate_M2(int steps, float speed){
distinguendo la rotate da rotate_M2
mi da errore
Scatto_Movimento_con_2_motori.cpp: In function 'void rotate_M1(int, float)':
:86: error: a function-definition is not allowed here before '{' token
:105: error: expected `}' at end of input
Il codice che mi da errore è questo:
int shutter_on = 200; //tempo di pressione per attivare la cam, da settare intorno i 100 e 300
int shutter_off = 1500; // tempo di attesa prima di attivare il motorino
int wakeup = 1000; //Tempo fuoco acceso
int wakewait =200; //time between wake and shutter
int outpin = 13; //uscita per lo scatto
int wakepin = 12; //uscita per la messa a fuoco
// init motorino
int DIR_PIN_M1 =7;
int STEP_PIN_M1 =5;
int SLEEP = 6; // PIN 12 = SLP
int DIR_PIN_M2 =2;
int STEP_PIN_M2 =3;
int delayTime = 500;
void setup() {
// init dei pin per lo scatto
pinMode(outpin, OUTPUT); //outpin gives output
pinMode(wakepin, OUTPUT); //wakepin gives output
// Tempo scatto Otturatore
shutter_on = 4000;
// init dei pin per il motorino
pinMode(DIR_PIN_M1, OUTPUT);
pinMode(STEP_PIN_M1, OUTPUT);
pinMode(SLEEP, OUTPUT); // set pin 12 to output
pinMode(DIR_PIN_M2, OUTPUT);
pinMode(STEP_PIN_M2, OUTPUT);
}
/////////// Loop ////////////
void loop(){
digitalWrite(wakepin, HIGH); //turn wakeup/focus on
delay(wakeup); //keep focus
digitalWrite(wakepin, LOW); //turn wakeup off
delay(wakewait); //wait
digitalWrite(outpin, HIGH); //press the shutter
delay(shutter_on); //wait the shutter release time
digitalWrite(outpin, LOW); //release shutter
delay(shutter_off); //wait for next round
//rotate a specific number of microsteps (8 microsteps per step)
//Avanti a 200 step
digitalWrite(SLEEP, HIGH); // Sveglia il motore.
rotate_M1(4000, 0.5);
rotate_M2(4000, 0.5);
digitalWrite(SLEEP, LOW); // Spegne il motore
delay(2000);
}
void rotate_M1(int steps, float speed){
//rotate a specific number of microsteps (8 microsteps per step) - (negitive for reverse movement)
//speed is any number from .01 -> 1 with 1 being fastest - Slower is stronger
int dir = (steps > 0)? HIGH:LOW;
steps = abs(steps);
digitalWrite(DIR_PIN_M1,dir);
float usDelay = (1/speed) * 70;
for(int i=0; i < steps; i++){
digitalWrite(STEP_PIN_M1, HIGH);
delayMicroseconds(usDelay);
digitalWrite(STEP_PIN_M1, LOW);
delayMicroseconds(usDelay);
}
void rotate_M2(int steps, float speed){
//rotate a specific number of microsteps (8 microsteps per step) - (negitive for reverse movement)
//speed is any number from .01 -> 1 with 1 being fastest - Slower is stronger
int dir = (steps > 0)? HIGH:LOW;
steps = abs(steps);
digitalWrite(DIR_PIN_M2,dir);
float usDelay = (1/speed) * 70;
for(int i=0; i < steps; i++){
digitalWrite(STEP_PIN_M2, HIGH);
delayMicroseconds(usDelay);
digitalWrite(STEP_PIN_M2, LOW);
delayMicroseconds(usDelay);
}
}
@uwefed si li programmo io.