improve touch filtering
This commit is contained in:
parent
c60f24e486
commit
4dd8599ab3
|
@ -7,11 +7,14 @@ uint16_t rawIn[INPUTS];
|
|||
uint16_t countedLow[INPUTS]; //count the times input was below threshold (touched)
|
||||
#define TOUCHTHRESHOLD 1000 //below which value input counts as touched. 0<x<1024
|
||||
#define COUNTEDLOWTHRESHOLD 10 //how many times input has to be sampled as low in a row to count as real touch.
|
||||
#define COUNTEDLOWTHRESHOLD_OFF 0
|
||||
// Inputdelay is given by: COUNTEDLOWTHRESHOLD*ADCREADINTERVAL
|
||||
|
||||
unsigned long last_adcmicros=0;
|
||||
#define ADCREADINTERVAL 2000 //in microseconds. interval to read all adc values
|
||||
|
||||
boolean last_output[INPUTS];
|
||||
|
||||
unsigned long last_send=0;
|
||||
#define MINIMUMSENDDELAY 10 //in milliseconds. minimum delay between serial sends
|
||||
|
||||
|
@ -62,7 +65,9 @@ void loop() {
|
|||
countedLow[i]=COUNTEDLOWTHRESHOLD; //upper limit. prevent overflow
|
||||
}
|
||||
}else{ //released or not pressed hard enough
|
||||
countedLow[i]=0; //reset counter
|
||||
if (countedLow[i]>0) {
|
||||
countedLow[i]--; //decrease counter
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -70,10 +75,19 @@ void loop() {
|
|||
|
||||
}
|
||||
|
||||
|
||||
for (uint8_t i=0;i<INPUTS;i++){ //for all keys
|
||||
if (countedLow[i]>=COUNTEDLOWTHRESHOLD) { //key pressed/touched
|
||||
last_output[i]=true;
|
||||
}else if (countedLow[i]<=COUNTEDLOWTHRESHOLD_OFF) { //key pressed/touched
|
||||
last_output[i]=false;
|
||||
}
|
||||
}
|
||||
|
||||
// ## Calculate Byte ##
|
||||
byte newTouch=0;
|
||||
for (uint8_t i=0;i<INPUTS;i++){ //for all keys
|
||||
if (countedLow[i]>=COUNTEDLOWTHRESHOLD) { //key pressed/touched
|
||||
if (last_output[i]) { //key pressed/touched
|
||||
newTouch^=1<<i;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue