From 539e0e1e974825f1d60975d6c5352d1b1927c22b Mon Sep 17 00:00:00 2001 From: Vasil Zlatanov Date: Thu, 4 May 2017 02:22:44 +0100 Subject: Add automatic threshold --- src/main.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index cf2214f..aa1b3b7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -17,7 +17,9 @@ Counter *switch_position[4]; Ticker timer; volatile uint16_t switch_count[4] = { 0, 0, 0, 0 }; +volatile uint16_t switch_pressed[4] = { 0, 0, 0, 0 }; volatile uint16_t update = 0; +uint16_t max_count[4]; // Initialise display SPInit gSpi(D_MOSI_PIN, NC, D_CLK_PIN); @@ -64,6 +66,14 @@ void tout(void) for (int i = 0; i < 3; ++i) { switch_count[i] = switch_position[i]->read(); switch_position[i]->write(0); + + if (max_count[i] < switch_count[i]) + max_count[i] = switch_count[i]; + + if (switch_count[i] < (3/5)*max_count[i]) + switch_pressed[i] = 1; + else if (switch_count[i] > (4/5)*max_count[i]) + switch_pressed[i] = 0; } // Update display update = 1; -- cgit v1.2.3