howdy. here's my code.
int lastvalue = 0;
void setup()
{
Serial.begin(9600);
}
void loop()
{
int value = minMax(3);
if(value != lastvalue)
{
Serial.println(value);
lastvalue = value;
}
}
int minMax(int pin)
{
int prevRead;
int output;
int THRESHOLD = 2;
int readVal = analogRead(pin); //read input from potentiometer
int readMap = map(readVal, 0, 1023, 0, 255);
if(abs(readMap - prevRead) >= THRESHOLD)
{
output = readMap;
prevRead = readMap;
}
return(output);
}
my problem/question is regarding this:
the THRESHOLD bit and the != lastval bit never seem to work when i try sticking them into a function other than void(main). why is that? also, in void(main), it only seems to work when the variables "threshold" and "prevX" and "lastX" are global.
can someone help clarify WHY?
without the "!= lastvalue" bit in void(main), serial.println will just print and print and print the output of int(minMax)
in my application, i need things to just print ONCE (rather, be sent once - serial print is just a way for me to see the data) and be done.
any direction would be great. i've pulled this off in void(main) a hundred times, but i've been taking C++ classes and would like to make my programs more modular with separate functions...
nym