Augusto Panecatl
/
PWM_RGB
PWM + RGB code example for FRDM-KL25Z
main.cpp@0:cb11ef198767, 2014-06-04 (annotated)
- Committer:
- APanecatl
- Date:
- Wed Jun 04 19:25:10 2014 +0000
- Revision:
- 0:cb11ef198767
Rev 1.0;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
APanecatl | 0:cb11ef198767 | 1 | #include "mbed.h" |
APanecatl | 0:cb11ef198767 | 2 | |
APanecatl | 0:cb11ef198767 | 3 | PwmOut Red(LED_RED); |
APanecatl | 0:cb11ef198767 | 4 | //PwmOut Green(LED_GREEN); |
APanecatl | 0:cb11ef198767 | 5 | |
APanecatl | 0:cb11ef198767 | 6 | |
APanecatl | 0:cb11ef198767 | 7 | |
APanecatl | 0:cb11ef198767 | 8 | int main() |
APanecatl | 0:cb11ef198767 | 9 | { |
APanecatl | 0:cb11ef198767 | 10 | Red.period_ms(2000); |
APanecatl | 0:cb11ef198767 | 11 | // Green.period(1000); |
APanecatl | 0:cb11ef198767 | 12 | // Red.pulsewidth_ms(500); |
APanecatl | 0:cb11ef198767 | 13 | int x; |
APanecatl | 0:cb11ef198767 | 14 | x=1; |
APanecatl | 0:cb11ef198767 | 15 | |
APanecatl | 0:cb11ef198767 | 16 | while(1) |
APanecatl | 0:cb11ef198767 | 17 | { |
APanecatl | 0:cb11ef198767 | 18 | Red.pulsewidth_ms(x); |
APanecatl | 0:cb11ef198767 | 19 | x=x+2; |
APanecatl | 0:cb11ef198767 | 20 | wait(1); |
APanecatl | 0:cb11ef198767 | 21 | if(x==1000) |
APanecatl | 0:cb11ef198767 | 22 | { |
APanecatl | 0:cb11ef198767 | 23 | x=1; |
APanecatl | 0:cb11ef198767 | 24 | } |
APanecatl | 0:cb11ef198767 | 25 | } |
APanecatl | 0:cb11ef198767 | 26 | |
APanecatl | 0:cb11ef198767 | 27 | } |