Hi everybody,
I’m having the following issue: I’m reading values from an accelerometer and I want to light up an LED only when a incremental “loops” variable will go over a set value (in this case 50). Right now, with the code below, if I move a little bit the accelerometer and stop it, “loops” will go to let’s say 35 and if I move the accelerometer the second time, it will continue from 35, go to 50 and only then reset to 0.
I want it to reset to 0 after each move, so I can use it as a threshold.
int loops = 0;
void loop() {
adcResult = < reading coming from accelerometer sensor >
if(adcResult > some_threshold_value){
loops +=1;
if(loops > 50){
analogWrite(ledPin, 127);
loops = 0;
}
}
}
It seems simple, but i can’t get to make it work .