Lab08 Oppgave 1 template
Dependencies: mbed
Import program
00001 #include "mbed.h" 00002 00003 PwmOut pwmLed(PB_9); 00004 00005 int main() 00006 { 00007 pwmLed.period(0.020); // 20ms Periode tid 00008 00009 //Set the led ouput duty-cycle to 1% 00010 float brightness=0.01; 00011 pwmLed=brightness; 00012 00013 printf("Press 'u' to turn LED1 brightness up, 'd' for down\n\r"); 00014 while(1) { 00015 00016 char c = getchar(); 00017 if((c == 'u') && (brightness < 0.1f)) 00018 brightness += 0.001f; 00019 if((c == 'd') && (brightness > 0.0f)) 00020 brightness -= 0.001f; 00021 00022 //Set the ouput duty-cycle, specified as a percentage 00023 pwmLed = brightness; 00024 printf("%c %1.3f \n \r",c,brightness); 00025 } 00026 } 00027
main.cpp@0:cf9946c35521, 2015-10-21 (annotated)
- Committer:
- rlanghbv
- Date:
- Wed Oct 21 09:50:57 2015 +0000
- Revision:
- 0:cf9946c35521
first commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rlanghbv | 0:cf9946c35521 | 1 | #include "mbed.h" |
rlanghbv | 0:cf9946c35521 | 2 | |
rlanghbv | 0:cf9946c35521 | 3 | PwmOut pwmLed(PB_9); |
rlanghbv | 0:cf9946c35521 | 4 | |
rlanghbv | 0:cf9946c35521 | 5 | int main() |
rlanghbv | 0:cf9946c35521 | 6 | { |
rlanghbv | 0:cf9946c35521 | 7 | pwmLed.period(0.020); // 20ms Periode tid |
rlanghbv | 0:cf9946c35521 | 8 | |
rlanghbv | 0:cf9946c35521 | 9 | //Set the led ouput duty-cycle to 1% |
rlanghbv | 0:cf9946c35521 | 10 | float brightness=0.01; |
rlanghbv | 0:cf9946c35521 | 11 | pwmLed=brightness; |
rlanghbv | 0:cf9946c35521 | 12 | |
rlanghbv | 0:cf9946c35521 | 13 | printf("Press 'u' to turn LED1 brightness up, 'd' for down\n\r"); |
rlanghbv | 0:cf9946c35521 | 14 | while(1) { |
rlanghbv | 0:cf9946c35521 | 15 | |
rlanghbv | 0:cf9946c35521 | 16 | char c = getchar(); |
rlanghbv | 0:cf9946c35521 | 17 | if((c == 'u') && (brightness < 0.1f)) |
rlanghbv | 0:cf9946c35521 | 18 | brightness += 0.001f; |
rlanghbv | 0:cf9946c35521 | 19 | if((c == 'd') && (brightness > 0.0f)) |
rlanghbv | 0:cf9946c35521 | 20 | brightness -= 0.001f; |
rlanghbv | 0:cf9946c35521 | 21 | |
rlanghbv | 0:cf9946c35521 | 22 | //Set the ouput duty-cycle, specified as a percentage |
rlanghbv | 0:cf9946c35521 | 23 | pwmLed = brightness; |
rlanghbv | 0:cf9946c35521 | 24 | printf("%c %1.3f \n \r",c,brightness); |
rlanghbv | 0:cf9946c35521 | 25 | } |
rlanghbv | 0:cf9946c35521 | 26 | } |
rlanghbv | 0:cf9946c35521 | 27 |