diff options
author | Vasil Zlatanov <v@skozl.com> | 2017-05-04 15:14:36 +0100 |
---|---|---|
committer | Vasil Zlatanov <v@skozl.com> | 2017-05-04 15:14:36 +0100 |
commit | bcf234f5883edb850d844ffceb9905c890d9498e (patch) | |
tree | 436105e51212bcde1389efe9680e1adc3ded4430 /src/main.cpp | |
parent | 02feeb68dcfe121b6bcb370001f63de3a7151b6b (diff) | |
download | e2-switch-bcf234f5883edb850d844ffceb9905c890d9498e.tar.gz e2-switch-bcf234f5883edb850d844ffceb9905c890d9498e.tar.bz2 e2-switch-bcf234f5883edb850d844ffceb9905c890d9498e.zip |
Add pwm function
Diffstat (limited to 'src/main.cpp')
-rw-r--r-- | src/main.cpp | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/src/main.cpp b/src/main.cpp index eecc5da..19f280d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7,14 +7,15 @@ #define SW_PERIOD 20000 // 20ms void tout(void); +void pwm_invert(void); // Onboard LED -DigitalOut alive(LED1); - +DigitalOut out_wave(LED1); PinName switch_pin[] = { SW_PINS }; Counter *switch_position[4]; -Ticker timer; +Ticker timer; +Ticker pwm; volatile uint16_t switch_count[4] = { 0, 0, 0, 0 }; volatile uint16_t switch_pressed[4] = { 0, 0, 0, 0 }; @@ -60,12 +61,15 @@ int main(void) uint16_t frequency = 1000*current_f[3] + 100*current_f[2] + 10*current_f[1] + current_f[0]; - oled.printf("\nF:%u F:%d", frequency, frequency); + oled.printf("\nF:%u ", frequency); + + if (frequency < 25) + pwm.attach_ms(&pwm_invert, 500/frequency); + else + pwm.attach_us(&pwm_invert, 500000/frequency); //Copy the display buffer to the display oled.display(); - - alive = !alive; } } @@ -90,3 +94,7 @@ void tout(void) // Update display update = 1; } + +void pwm_invert(void){ + out_wave = !out_wave; +} |