Intenzitet diode
Dependencies: mbed
Fork of Fistrek_sinus by
Revision 5:3dcf87833bbb, committed 2015-12-10
- Comitter:
- ffistrek
- Date:
- Thu Dec 10 17:42:33 2015 +0000
- Parent:
- 4:a3ec775f889b
- Commit message:
- Fistrek_intenzitet diode
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Thu Dec 10 16:46:10 2015 +0000 +++ b/main.cpp Thu Dec 10 17:42:33 2015 +0000 @@ -1,15 +1,28 @@ +// host terminal LED dimmer control #include "mbed.h" -#define INPUT_SCALAR (0.01f) -AnalogIn Ain(p20); - AnalogOut Aout(p18); - float i; - float pi=3.14159; - int main() - { - while(1) { - for (i=0; i<2; i=i+0.005) { - Aout=0.5+0.5*sin(i*pi); - wait(Ain*INPUT_SCALAR); - } - } - } \ No newline at end of file +Serial pc(USBTX, USBRX); // tx, rx +PwmOut PWM1(p21); +float brightness=0.0; +int main() { +PWM1.period(0.010); // set PWM period to 10 ms +PWM1=0.8; // set duty cycle to 80% +pc.printf("Control of LED dimmer by host terminal\n\r"); +pc.printf("Press 'u' = brighter, 'd' = dimmer\n\r"); +while(1) { +char c = pc.getc(); +wait(0.001); +if((c == 'u') && (brightness < 1.0)) { +brightness += 0.1; +PWM1= brightness; +} +if((c == 'd') && (brightness > 0.0)) { +brightness -= 0.1; +PWM1= brightness; +} +if(c == 'x'){ +brightness = 0.5; +PWM1 = brightness; +} +pc.printf("%c %1.3f \n \r",c,brightness); +} +}