Compiling Error

Hi All,

Hope you can help me, I am trying to write a short program (shown below) that when a button is pressed it rewinds the motor. It keeps coming up with "'Rloop' cannot be used as a function"

#include <AccelStepper.h>

const int Rewindbutton = 6;
int current;
long millis_held;
long prev_millis_held;
unsigned long firstTime;
//AccelStepper Rewind(1, 5, 4); // pin 5 = step, pin 4 = direction
AccelStepper Rewind(1, 5, 4);

void setup() {
Rewind.setMaxSpeed(1250);
Rewind.setSpeed(1250);

}

void loop()
{
int Rloop;
millis_held = (millis() - firstTime);
current = digitalRead(Rewindbutton);

if (millis_held > 50){
if (current == LOW && millis_held > prev_millis_held)Rloop();
}

void Rloop() {
Rewind.runSpeed();
}

Thanks

Steve_H

You have a variable Rloop of type int (in loop()) and a function Rloop(). Rename one of the two.

Please post code in future using code tags. You can edit your post and place [code] before your code and [/code] after it.

Hi Sterretje,

Thanks for the reply, I'm a newbie at this. The int Rloop was a mistake, what I am trying to do is get the

"if (current == LOW && millis_held > prev_millis_held)Rloop();"

to call up the Rloop subroutine. But with the int Rloop removed it says the Rloop in the the line above was not declared :-S

Hope you can help

Thanks again

Try using Tools + Auto Format. It will tell you that the number of { in your code does not match the number of }.

Your Rloop() function is defined inside the loop() function, which is not allowed.

Rloop() is a lousy name. I can't even begin to guess what that function is doing.

PaulS:
Rloop() is a lousy name. I can't even begin to guess what that function is doing.

How about RewindLoop :wink: But in a few years time OP will no longer remember :smiley:

But I indeed will make it longer (usually I type it out completely). Bigger problem is that it's not a loop and hence the name rewind is more suitable :wink: