Pages: [1]   Go Down
Author Topic: Passing Parameter for use in motor.step  (Read 735 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 17
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 614
Posts: 49372
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#define FORWARD 1
and
Code:
void AF_Stepper::step(uint16_t steps, [glow]uint8_t dir[/glow],  uint8_t style);
« Last Edit: January 14, 2011, 06:49:56 am by PaulS » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 17
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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");
 }
Logged

Pages: [1]   Go Up
Jump to: