using DAC0_OUT to adjust the brightness of a led

Committer:
namcheol
Date:
Wed Apr 15 07:31:03 2020 +0000
Revision:
1:aa352db03d0c
Parent:
0:f31836d48420
lab02-led-dimmer

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dshin 0:f31836d48420 1 #include "mbed.h"
dshin 0:f31836d48420 2
namcheol 1:aa352db03d0c 3 AnalogOut led(DAC0_OUT); //led = DAC0_OUT
dshin 0:f31836d48420 4
dshin 0:f31836d48420 5 int main()
dshin 0:f31836d48420 6 {
namcheol 1:aa352db03d0c 7 float f;
namcheol 1:aa352db03d0c 8
dshin 0:f31836d48420 9 while (true) {
namcheol 1:aa352db03d0c 10 for(f = 0.5; f <= 1.0; f += 0.01){ //led from 50% of brightness to 100%
namcheol 1:aa352db03d0c 11 led.write(f);
namcheol 1:aa352db03d0c 12 thread_sleep_for(3000/50);
namcheol 1:aa352db03d0c 13 }
namcheol 1:aa352db03d0c 14 for(f = 1.0; f >= 0.5; f -= 0.01){ //led from 100% to 50%
namcheol 1:aa352db03d0c 15 led.write(f);
namcheol 1:aa352db03d0c 16 thread_sleep_for(3000/50);
namcheol 1:aa352db03d0c 17 }
dshin 0:f31836d48420 18 }
dshin 0:f31836d48420 19 }