Dear Forum members, this is the first time I use the Forum, however, I have been using Arduino for a while.
Apologies if I make any mistakes using the Forum, such as choosing wrong category or adressing the wrong participants. My goal was to send a question to the whole Forum in the appropriate category.
I am trying to further develop my coding skills by using functions and arrays, making codes cleaner and more efficient. The code posted below returns several erros of the same kind (example below):
Blockquote
sketch.ino:31:19: error: variable or field 'stepM1Run' declared void
void stepM1Run(stepBM1,stepEM1,amplitudeM1);
^~~~~~~
sketch.ino:32:19: error: variable or field 'stepM1Run' declared void
void stepM1Run(stepBM1,stepEM1,amplitudeM1) {
^~~~~~~
Blockquote
I have tried finding solutions for a while now. I have tried moving the functions to the top, bottom, but nothing seems to work. The code controls 2 stepper motors without using libraries. It works perfectly in version one without the functions and arrays.
could you please try to help?
Thank you.
Full code posted below.
// stepper2
// defines pins
const int openSensorPin = 2;
const int closeSensorPin = 3;
const int stepPinM1 = 4;
const int dirPinM1 = 5;
const int stepPinM2 = 9;
const int dirPinM2 = 10;
// defines variables
int stepBM1[13] = {1,2,3,4,5,6,7,8,9,10,11,12,13};
int stepEM1[13] = {1,2,3,4,5,6,7,8,9,10,11,12,13};
int amplitudeM1[13] = {1,2,3,4,5,6,7,8,9,10,11,12,13};
int stepBM2[13] = {1,2,3,4,5,6,7,8,9,10,11,12,13};
int stepEM2[13] = {1,2,3,4,5,6,7,8,9,10,11,12,13};
int amplitudeM2[13] = {1,2,3,4,5,6,7,8,9,10,11,12,13};
int i = 0;
int stepMotorM1 = 0;
int stepMotorM2 = 0;
// Define Functions
void stepM1Run(stepBM1,stepEM1,amplitudeM1);
void stepM1Run(stepBM1,stepEM1,amplitudeM1) {
for(stepMotorM1 = int stepBM1; stepMotorM1 < int stepEM1; stepMotorM1++) {
digitalWrite(stepPinM1,HIGH);
delayMicroseconds(int amplitudeM1);
digitalWrite(stepPinM1,LOW);
delayMicroseconds(int amplitudeM1);
}
}
void stepM2Run(stepBM2,stepEM2,amplitudeM2);
void stepM2Run(stepBM2,stepEM2,amplitudeM2){
for(stepMotorM2 = int stepBM2; stepMotorM2 < int stepEM2; stepMotorM2++) {
digitalWrite(stepPinM2,HIGH);
delayMicroseconds(int amplitudeM2);
digitalWrite(stepPinM2,LOW);
delayMicroseconds(int amplitudeM2);
}
}
void setup() {
//sets serial
Serial.begin(9600);
// sets pins
pinMode (openSensorPin,INPUT_PULLUP);
pinMode (closeSensorPin,INPUT_PULLUP);
pinMode(stepPinM1,OUTPUT);
pinMode(dirPinM1,OUTPUT);
pinMode (stepPinM2,OUTPUT);
pinMode (dirPinM2,OUTPUT);
}
void loop() {
// Open Routine
if (digitalRead (openSensorPin) == LOW) {
digitalWrite(dirPinM1,LOW);
digitalWrite(dirPinM2,LOW);
for(i=0;i<=12;i++) {
stepM1Run(stepBM1[i], stepEM1[i], amplitudeM1[i]);
stepM2Run(stepBM2[i], stepEM2[i], amplitudeM2[i]);
}
}
// Close Routine
if(digitalRead(closeSensorPin) == LOW); {
digitalWrite(dirPinM1,HIGH);
digitalWrite(dirPinM2,HIGH);
for(i=0;i<=12;i++) {
stepM1Run(stepBM1[i], stepEM1[i], amplitudeM1[i]);
stepM2Run(stepBM2[i], stepEM2[i], amplitudeM2[i]);
}
}
}