summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVasil Zlatanov <v@skozl.com>2017-05-08 10:14:24 +0100
committerVasil Zlatanov <v@skozl.com>2017-05-08 10:14:24 +0100
commit3b6bce92d0ea349e744daea8f84a703feec832a5 (patch)
treec45f624a2b856fa5348417d56f0edcbc67a8f0eb /src
parent12250f63813c329257523e2cb48792c51590dd9e (diff)
downloade2-switch-3b6bce92d0ea349e744daea8f84a703feec832a5.tar.gz
e2-switch-3b6bce92d0ea349e744daea8f84a703feec832a5.tar.bz2
e2-switch-3b6bce92d0ea349e744daea8f84a703feec832a5.zip
Fix attach_us being called too often, remove workaround
Diffstat (limited to 'src')
-rw-r--r--src/main.cpp26
1 files changed, 11 insertions, 15 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 1af96d5..4ceb98e 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -9,7 +9,6 @@
void tout(void);
void pwm_invert_fast(void);
-void pwm_invert_slow(void);
// Onboard LED
DigitalOut out_wave(LED1);
@@ -34,6 +33,9 @@ Adafruit_SSD1306_Spi oled(gSpi, D_DC_PIN, D_RST_PIN, D_CS_PIN, 64, 128);
int main(void)
{
+ uint16_t frequency = 0;
+ uint16_t old_frequency = 0;
+
out_wave.write(0.5);
oled.setRotation(2);
wait(0.5);
@@ -63,15 +65,17 @@ int main(void)
oled.printf("\nS:%u C:%05u N:%u", switch_pressed[i], switch_count[i], current_f[i]);
}
- uint16_t frequency = 1000*current_f[3] + 100*current_f[2] + 10*current_f[1] + current_f[0];
+ old_frequency = frequency;
+ frequency = 1000*current_f[3] + 100*current_f[2] + 10*current_f[1] + current_f[0];
+
+ if (frequency != old_frequency){
- oled.printf("\nF:%u ", frequency);
+ oled.printf("\nF:%u ", frequency);
- if (frequency > 24)
- pwm.attach_us(&pwm_invert_fast, 500000/frequency);
- else if (frequency > 0)
- pwm.attach_us(&pwm_invert_slow, 25000/frequency);
+ if (frequency)
+ pwm.attach_us(&pwm_invert_fast, 500000/frequency);
+ }
//Copy the display buffer to the display
oled.display();
}
@@ -99,14 +103,6 @@ void tout(void)
update = 1;
}
-void pwm_invert_slow(void){
- divider++;
- if (divider % 25 == 0){
- divider = 0;
- out_wave = !out_wave;
- }
-}
-
void pwm_invert_fast(void){
out_wave = !out_wave;
}