I have done an extensive search and unable to find answer probably because its obvious to everyone else.
I am trying to pass a parameter to use in function to move stepper motor in a direction
#include <AFMotor.h>
int sensorPin = 0; // select the input pin for the potentiometer
int sensorValue = 0; // variable to store the value coming from the sensor
int steps[36];
AF_Stepper motor(48, 2);
byte currentPos = 0;
void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println("Stepper test!");
motor.setSpeed(50); // 10 rpm
}
void loop() {
getvalsR(FORWARD); // here is my call ****************
delay(5000);
}
void getvalsR(String Direction) { //Function to check each postion light reading and store in array
for(byte x=0; x < 35; x = x + 1){
sensorValue = analogRead(sensorPin);
Serial.print(x);
Serial.print(" = ");
Serial.println(sensorValue);
steps[x] = sensorValue;
motor.step(1, Direction, SINGLE); //This is what fails
delay(1000);
}
}
Compile error is "no matching function for call to 'AF_Stepper::step(int, String&,int)' I have tried enclosing the "Direction" in all sort of brackets etc
I would greatly appreaciate any help
cheers
Your function is defined to take a String. FORWARD is not a String.
You pass the argument that your function receives to AF_Stepper::step(), which is not defined to accept a String.
You should find where FORWARD is defined, and see what it's type is. You should find where AF_Stepper::step() is defined, and see what type the arguments supplied to it need to be. You should define your function to accept an argument of the type that AF_Stepper::step() expects.
Brilliant thanks PaulS, my programming skills are somewhat rusty but eventually worked it out, not sure if it is elegant but at least it works now.
#include <AFMotor.h>
int sensorPin = 0; // select the input pin for the potentiometer
int sensorValue = 0; // variable to store the value coming from the sensor
int steps[20];
AF_Stepper motor(48, 2);
byte currentPos = 0;
void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println("Stepper test!");
motor.setSpeed(100); // 10 rpm
}
void loop() {
getvalsR(FORWARD);
delay(1000);
getvalsR(BACKWARD);
delay(1000);
}
void getvalsR(uint8_t dir) { //Function to check each postion light reading and store in array
for(byte x=0; x < 19; x = x + 1){
sensorValue = analogRead(sensorPin);
Serial.println(sensorValue);
steps[x] = sensorValue;
motor.step(1, dir, SINGLE);
delay(500);
}
Serial.println("End");
}