summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVasil Zlatanov <v@skozl.com>2017-05-04 13:10:43 +0100
committerVasil Zlatanov <v@skozl.com>2017-05-04 13:10:43 +0100
commit023907a7e67c01e4b2d263b57377c55f3101aec7 (patch)
treeb56e7c471b5fcf5dcbef433d41ddb57eadd9f0a7
parentdbd3428936db3298550fcd65b736a14ab032a3ad (diff)
downloade2-switch-023907a7e67c01e4b2d263b57377c55f3101aec7.tar.gz
e2-switch-023907a7e67c01e4b2d263b57377c55f3101aec7.tar.bz2
e2-switch-023907a7e67c01e4b2d263b57377c55f3101aec7.zip
Buttons set frequency
-rw-r--r--src/main.cpp19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 33bb55c..8deca7b 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -3,7 +3,7 @@
#include "counter.h"
#include "Adafruit_SSD1306.h"
-#define SW_PINS p22, p23, p24, p25
+#define SW_PINS p25, p24, p24, p22
#define SW_PERIOD 20000 // 20ms
void tout(void);
@@ -18,6 +18,10 @@ 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 last_pressed[4] = { 0, 0, 0, 0 };
+
+uint16_t current_f[4] = { 0, 0, 0, 0 };
+
volatile uint16_t update = 0;
uint16_t max_count[4];
@@ -47,11 +51,18 @@ int main(void)
oled.setTextCursor(0, 0);
+ int frequency = 0;
//Write the latest switch osciallor count
- for (int i = 0; i < 4; ++i) {
- oled.printf("\nS:%u C:%05u", switch_pressed[i], switch_count[i]);
+ for (int i = 3; i >= 0; --i) {
+ current_f[i] += (switch_pressed[i] && !last_pressed[i]);
+ if (current_f[i] > 9)
+ current_f[i] = 0;
+
+ frequency += current_f[i] * (10^i);
+ oled.printf("\nS:%u C:%05u N:%u", switch_pressed[i], switch_count[i], current_f[i]);
}
+ oled.printf("\nF:%u F:%d", frequency, frequency);
//Copy the display buffer to the display
oled.display();
@@ -70,6 +81,8 @@ void tout(void)
for (int i = 0; i < 4; ++i) {
switch_count[i] = switch_position[i]->read();
switch_position[i]->write(0);
+
+ last_pressed[i] = switch_pressed[i];
if (max_count[i] < switch_count[i])
max_count[i] = switch_count[i];