Go Down

Topic: Passing Parameter for use in motor.step (Read 851 times) previous topic - next topic

rubberbrick

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

Quote
#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
  • = 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

PaulS

#1
Jan 14, 2011, 12:49 pm Last Edit: Jan 14, 2011, 12:49 pm by PaulS Reason: 1
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.

In case you get lost, AFMotor.h contains
Code: [Select]
#define FORWARD 1
and
Code: [Select]
void AF_Stepper::step(uint16_t steps, [glow]uint8_t dir[/glow],  uint8_t style);

rubberbrick

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.

Code: [Select]
#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");
}

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy