The problem with this coding is fsrReading > 10 && fsrReading < 350 , the sensor will keep counting...
What i want is, if the FSR detect range 10 - 350 , the counter just count 1 only... From my code above, the sensor will keep counting when the sensor in the range..
I try to do in this way .. Let say if the FSR detect in range 10 - 350, the count will start count 1 and stay 1 if still in the range.. Then when it below 10, the counter will not count and then, it count 1 again when reach within the range. (just only one not will continously counting if still in the range)
Refer to the code you give..
I had try and the result still continuous counting when in range threshold..
is it possible arduino count just only 1 if it in threshold...(not continuous count).
because i want to make FSR as a step counter.
but the problem is when it in range threshold, the counter will continuously counting.
When a person step on a FSR, it will count and doesnt matter how long time it step on the FSR.the FSR will count 1 and if he/she make another step, it will count as 2..
I was a bit surprised by this at first, but I get excellent results by treating an FSR exactly like a tact switch. The code below illustrates this, using a debounce library that I wrote. I have the FSR connected to A0, but it is used as a digital input; any digital or analog pin can be used. I use the AVR's internal pullup so no external resistors are required.
//Counter using a Force-Sensitive Resistor (FSR) as input.
//Connect the FSR from the designated pin to ground, with no
//pullup or pull-down resistors.
//Works with this FSR https://www.sparkfun.com/products/9376
#include <Button.h> //http://github.com/JChristensen/Button
#define FSR_PIN A0 //connect fsr from this pin to ground
#define PULLUP true //use the AVR's internal pullup resistor
#define INVERT true //low level means fsr pressed
#define DEBOUNCE_TIME 50 //milliseconds
Button fsr = Button(FSR_PIN, PULLUP, INVERT, DEBOUNCE_TIME);
int counter;
void setup(void)
{
Serial.begin(9600);
}
void loop(void)
{
fsr.read();
if (fsr.wasPressed()) {
Serial.print(++counter, DEC);
Serial.println(" steps");
}
}
The problem with this coding is fsrReading > 10 && fsrReading < 350 , the sensor will keep counting...
What i want is, if the FSR detect range 10 - 350 , the counter just count 1 only... From my code above, the sensor will keep counting when the sensor in the range..
Do you want your counter to increment one time for each time the (FSR) reading goes from outside your range to inside it? In that case, you need a variable (one that keeps its value between calls to loop) to hold the previous state, namely inside vs. outside the signal band of interest. So, I think you may want something like:
static boolean prevInRange = false; // persistent variable for previous state
void loop()
{
int fsrVal;
int count = 0;
boolean curInRange;
fsrVal = analogRead(FSR_PIN);
if ((fsrVal >= LOW_THRESH) && (fsr_val <= HIGH_THRESH)) { // is FSR inside defined band?
curInRange = true;
}
if ( (prevInRange == false) && (curInRange == true)) { // then we've just transitioned into the band
count +=1; // increment once per outside-to-inside transition
}
prevInRange = curInRange; // update history for next time