Lee Nam Cheol
/
lab02-led-dimmer
using DAC0_OUT to adjust the brightness of a led
Revision 1:aa352db03d0c, committed 2020-04-15
- Comitter:
- namcheol
- Date:
- Wed Apr 15 07:31:03 2020 +0000
- Parent:
- 0:f31836d48420
- Commit message:
- lab02-led-dimmer
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Sun Mar 29 19:41:28 2020 +0000 +++ b/main.cpp Wed Apr 15 07:31:03 2020 +0000 @@ -1,18 +1,19 @@ #include "mbed.h" -// https://os.mbed.com/docs/mbed-os/v5.15/tools/creating-a-new-program.html - -Serial pc(USBTX, USBRX, 115200); // baud rate 115200 -DigitalOut led(LED1); // led = LED1 +AnalogOut led(DAC0_OUT); //led = DAC0_OUT int main() { + float f; + while (true) { - led = 0; - printf("LED1 is ON\r\n"); - thread_sleep_for(500); - led = 1; - printf("LED1 is OFF\r\n"); - thread_sleep_for(500); + for(f = 0.5; f <= 1.0; f += 0.01){ //led from 50% of brightness to 100% + led.write(f); + thread_sleep_for(3000/50); + } + for(f = 1.0; f >= 0.5; f -= 0.01){ //led from 100% to 50% + led.write(f); + thread_sleep_for(3000/50); + } } } \ No newline at end of file