system
1
OK sorry struggling with the concept of functions
http://www.arduino.cc/playground/Main/Autoscale
Trying to use autoscale where I want to get rid of the test stuff and use as a function, is this possible i'm sure it is.
Im guessing ill be passing something like :
autoScale(50,100,0,255); but how do I get stuff back?
Any help would be grateful as i'm sure when I understand how to convert this into a function ill get the hang of them.
TIA
system
2
autoScale(50,100,0,255); but how do I get stuff back?
This function definition:
int autoScale( int originalMin, int originalMax, int newBegin, int
newEnd, int inputValue) {...
means that the function will return an int
value (that's what the first int
in that line means).
To get access to what the function is returning, you need to tell it where to put it. That's what this line from the sample code is doing:
scaledResult = autoScale( -50, 75, 50, -50, j);
So the result is now stored in the variable named scaledResult
.
You need to do something similar in your code.
--Phil.
system
3
so you dont have to do somthing like this then for a function?
void autoScale()
{
some stuff here
}
system
4
Yes, you can do it that way if you aren't going to have any returned values. Here's that reference page on "void".
http://www.arduino.cc/en/Reference/Void
system
5
so you dont have to do somthing like this then for a function?
void autoScale()
{
some stuff here
}
Can you please elaborate on what you're asking here, I'm not sure I follow.
--Phil.