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.
Fork of blink_kl46z_LCD by
main.cpp@2:24090ed5f981, 2014-09-03 (annotated)
- Committer:
- scohennm
- Date:
- Wed Sep 03 15:03:30 2014 +0000
- Revision:
- 2:24090ed5f981
- Parent:
- 0:e23fffd4b9a7
- Child:
- 3:f445e67012ee
Example of the use of PWM for the KL46Z. Used for algorithms class at NMHU
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| scohennm | 0:e23fffd4b9a7 | 1 | #include "mbed.h" | 
| scohennm | 0:e23fffd4b9a7 | 2 | #define LEDON false | 
| scohennm | 0:e23fffd4b9a7 | 3 | #define LEDOFF true | 
| scohennm | 2:24090ed5f981 | 4 | #define PWMDWELL 50// milliseconds | 
| scohennm | 2:24090ed5f981 | 5 | #define DFDELTA 0.01 | 
| scohennm | 0:e23fffd4b9a7 | 6 | |
| scohennm | 0:e23fffd4b9a7 | 7 | // slightly more interesting blinky 140814 sc | 
| scohennm | 2:24090ed5f981 | 8 | // Change to use PWM | 
| scohennm | 0:e23fffd4b9a7 | 9 | |
| scohennm | 2:24090ed5f981 | 10 | float dutyFactor = 0.0; | 
| scohennm | 2:24090ed5f981 | 11 | PwmOut greenColor(LED_GREEN); | 
| scohennm | 2:24090ed5f981 | 12 | PwmOut redColor(LED_RED); | 
| scohennm | 0:e23fffd4b9a7 | 13 | |
| scohennm | 0:e23fffd4b9a7 | 14 | int main() { | 
| scohennm | 0:e23fffd4b9a7 | 15 | while(true) { | 
| scohennm | 2:24090ed5f981 | 16 | redColor.write(dutyFactor); | 
| scohennm | 2:24090ed5f981 | 17 | greenColor.write(1.0 - dutyFactor); | 
| scohennm | 2:24090ed5f981 | 18 | dutyFactor += DFDELTA; | 
| scohennm | 2:24090ed5f981 | 19 | if(dutyFactor >= 1.0) dutyFactor = 0.0; | 
| scohennm | 2:24090ed5f981 | 20 | wait_ms(PWMDWELL); | 
| scohennm | 0:e23fffd4b9a7 | 21 | } | 
| scohennm | 0:e23fffd4b9a7 | 22 | } | 
