system
#1
Howdy.
Please forgive my noobness, but how do I pass parameters to a function eg:
void loop()
{
MyFunction(1000);
}
void MyFunction
{
X = the vaule passed from the function call
}
Basically I want to tell my function a value, just as you would use a library call eg: thing.attach(1);
value 1 gets passed to the function and I can use the it as a variable.
Cheers.
system
#2
Howdy.
Please forgive my noobness, but how do I pass parameters to a function eg:
void loop()
{
MyFunction(1000);
}
void MyFunction
{
X = the vaule passed from the function call
}
Like this:
void loop()
{
MyFunction(1000);
}
void MyFunction( int x )
{
//x = the vaule passed from the function call
}
system
#3
Hi,
I have tried that^ but now get:
" In function ‘void loop()’:
error: ‘fwd_slowstop’ was not declared in this scope At global scope:"
Here is my updated code:
void loop()
{
fwd_slowstop(1000);
}
void fwd_slowstop(int duration);
{
int delaytime;
delaytime = (duration / 20;)
for (int i=70; i <=90 ; i++){
servo.write(i);
delay(delaytime);
}
}
system
#4
Got it sorted thanks.
void loop()
{
fwd_slowstop(1000);
delay(5000);
}
void fwd_slowstop(int duration)
{
int delaytime;
delaytime = (duration / 20);
for (int i=70; i <=90 ; i++){
servo.write(i);
delay(delaytime);
}
}
The only reason it did not work first time around was because you have a semi-colon after the function declaration..
void fwd_slowstop(int duration);
1 Like