Sikil
/
Sikil
Sikil
Diff: main.cpp
- Revision:
- 0:ca4ecd424807
diff -r 000000000000 -r ca4ecd424807 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Jan 15 09:51:57 2021 +0000 @@ -0,0 +1,38 @@ +/* Sikil + */ + +#include "mbed.h" +#include "platform/mbed_thread.h" + +int main() +{ + DigitalOut led(LED1); + Serial computer(USBTX, USBRX); + + computer.baud(9600); + computer.printf("Press 'u' to turn LED brightness up, 'd' to turn it down\n"); + + float brightness{1.f}; + static constexpr int duty_cycle_ms{10}; + + while (true) { + if (computer.readable()) { + char letter = computer.getc(); + + if((letter == 'u') && (brightness < 1.f)) { + brightness += 0.1f; + led = brightness; + } + + if((letter == 'd') && (brightness > 0.f)) { + brightness -= 0.1f; + led = brightness; + } + } + + led = 1; + thread_sleep_for(brightness * duty_cycle_ms); + led = 0; + thread_sleep_for((1.f - brightness) * duty_cycle_ms); + } +}