Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
main.cpp@2:549ed5b0a8d0, 2016-11-10 (annotated)
- Committer:
- imihalj
- Date:
- Thu Nov 10 17:43:03 2016 +0000
- Revision:
- 2:549ed5b0a8d0
- Parent:
- 1:d5b594dc8056
- Child:
- 3:798a084f105a
vjezba3
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
imihalj | 0:c32036656bb4 | 1 | #include "mbed.h" |
imihalj | 2:549ed5b0a8d0 | 2 | Serial pc(USBTX, USBRX); // tx, rx |
imihalj | 2:549ed5b0a8d0 | 3 | PwmOut PWM1(p21); |
imihalj | 2:549ed5b0a8d0 | 4 | float brightness=0.0; |
imihalj | 0:c32036656bb4 | 5 | int main() |
imihalj | 0:c32036656bb4 | 6 | { |
imihalj | 2:549ed5b0a8d0 | 7 | PWM1.period(0.010); // set PWM period to 10 ms |
imihalj | 2:549ed5b0a8d0 | 8 | PWM1=0.8; // set duty cycle to 80% |
imihalj | 2:549ed5b0a8d0 | 9 | pc.printf("Control of LED dimmer by host terminal\n\r"); |
imihalj | 2:549ed5b0a8d0 | 10 | pc.printf("Press 'u' = brighter, 'd' = dimmer\n\r"); |
imihalj | 0:c32036656bb4 | 11 | while(1) { |
imihalj | 2:549ed5b0a8d0 | 12 | char c = pc.getc(); |
imihalj | 2:549ed5b0a8d0 | 13 | wait(0.001); |
imihalj | 2:549ed5b0a8d0 | 14 | if((c == 'u') && (brightness < 1.0)) { |
imihalj | 2:549ed5b0a8d0 | 15 | brightness += 0.1; |
imihalj | 2:549ed5b0a8d0 | 16 | PWM1= brightness; |
imihalj | 1:d5b594dc8056 | 17 | } |
imihalj | 2:549ed5b0a8d0 | 18 | if((c == 'd') && (brightness > 0.0)) { |
imihalj | 2:549ed5b0a8d0 | 19 | brightness -= 0.1; |
imihalj | 2:549ed5b0a8d0 | 20 | PWM1= brightness; |
imihalj | 2:549ed5b0a8d0 | 21 | } |
imihalj | 2:549ed5b0a8d0 | 22 | pc.printf("%c %1.3f \n \r",c,brightness); |
imihalj | 0:c32036656bb4 | 23 | } |
imihalj | 0:c32036656bb4 | 24 | } |