diff --git a/touchcontroller/touchcontroller.ino b/touchcontroller/touchcontroller.ino index 0874cd3..4045261 100644 --- a/touchcontroller/touchcontroller.ino +++ b/touchcontroller/touchcontroller.ino @@ -8,11 +8,10 @@ uint16_t countedLow[INPUTS]; //count the times input was below threshold (touche #define COUNTEDLOWTHRESHOLD 10 //how many times input has to be sampled as low in a row to count as real touch. // Inputdelay is given by: COUNTEDLOWTHRESHOLD*ADCREADINTERVAL -long last_adcmicros=0; +unsigned long last_adcmicros=0; #define ADCREADINTERVAL 2000 //in microseconds. interval to read all adc values -boolean inputchangeFlag; //flag to update keypress -long last_send=0; +unsigned long last_send=0; #define MINIMUMSENDDELAY 10 //in milliseconds. minimum delay between serial sends void setup() { @@ -28,7 +27,7 @@ void setup() { } void loop() { - long loopmillis=millis(); + unsigned long loopmillis=millis(); // ## Sampling and Touch Filtering ## if (micros()-last_adcmicros>=ADCREADINTERVAL) @@ -52,34 +51,30 @@ void loop() { countedLow[i]++; //increase counter if (countedLow[i]>=COUNTEDLOWTHRESHOLD) { //upper limit countedLow[i]=COUNTEDLOWTHRESHOLD; //upper limit. prevent overflow - inputchangeFlag=true; //flag to update keypress } }else{ //released or not pressed hard enough countedLow[i]=0; //reset counter - inputchangeFlag=true; //flag to update keypress } } } + // ## Calculate Byte ## + byte newTouch=0; + for (uint8_t i=0;i=COUNTEDLOWTHRESHOLD) { //key pressed/touched + newTouch^=1<MINIMUMSENDDELAY) //delay between last send long enough - { - touchOut = 0; //reset bits - for (uint8_t i=0;i=COUNTEDLOWTHRESHOLD) { //key pressed/touched - touchOut^=1<MINIMUMSENDDELAY) //delay between last send long enough + { + if (newTouch!=touchOut) { //touched keys have changed + touchOut=newTouch; //update last_send=loopmillis; - inputchangeFlag=false; //clear Flag + //Serial.println(touchOut, BIN); + Serial.write(touchOut); //Send byte } }