Skip to content

Commit

Permalink
lower touch threshold for hopefully more s/n ratio, speed up startup …
Browse files Browse the repository at this point in the history
…demo
  • Loading branch information
todbot committed Oct 23, 2024
1 parent cc50789 commit e7b2f06
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
17 changes: 11 additions & 6 deletions firmware/TouchwheelSAO_attiny816/TouchwheelSAO_attiny816.ino
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#define MY_I2C_ADDR 0x54
#define LED_BRIGHTNESS 80 // range 0-255
#define LED_UPDATE_MILLIS (2)
#define TOUCH_THRESHOLD_ADJ (1.2)
#define TOUCH_THRESHOLD_ADJ (1.1)
#define FPOS_FILT (0.05)

// note these pin numbers are the megatinycore numbers:
Expand Down Expand Up @@ -154,7 +154,7 @@ void startup_demo() {
ledr = i, ledg = i, ledb = i;
pixel_fill(ledr, ledg, ledb);
pixel_show();
delay(10);
delay(5);
}
for(byte i=0; i<255; i++) {
for(byte n=0; n<3; n++) {
Expand All @@ -164,7 +164,7 @@ void startup_demo() {
pixel_set(n, r,g,b);
}
pixel_show();
delay(10);
delay(5);
}
}

Expand All @@ -184,17 +184,22 @@ void setup() {
touches[i].begin( touch_pins[i] );
touches[i].threshold = touches[i].raw_value * TOUCH_THRESHOLD_ADJ; // auto threshold doesn't work
}
//touch_recalibrate();
}

void touch_recalibrate() {
for( int i=0; i< touch_count; i++) {
uint16_t v = touches[i].recalibrate();
touches[i].threshold = v * TOUCH_THRESHOLD_ADJ; // auto threshold doesn't work
}
}

// main loop
void loop() {
if(do_startup_demo) {
startup_demo();
// recalibrate in case pads were being touched on power up (or power not stable)
for( int i=0; i< touch_count; i++) {
touches[i].threshold = touches[i].raw_value * TOUCH_THRESHOLD_ADJ; // auto threshold doesn't work
}
//touch_recalibrate();
do_startup_demo = false;
}

Expand Down
4 changes: 3 additions & 1 deletion firmware/TouchwheelSAO_attiny816/TouchyTouch.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,16 @@ class TouchyTouch

/*!
@brief Recalibrate threshold value, called automatically on begin().
Returns an optional smoothed raw_value to use for hand recalibration
*/
void recalibrate() {
uint16_t recalibrate() {
const int num_reads = 5;
for(int i=0; i<num_reads; i++) {
raw_value += rawRead();
}
raw_value /= num_reads;
threshold = (raw_value * 1.05) + 100;
return raw_value;
}

/*!
Expand Down

0 comments on commit e7b2f06

Please sign in to comment.