![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
LPC800-MAX RGB demo using SCT and MRT
LPC800-MAX RGB demo using State-Configurable Timer(SCT) and Multi-Rate Timer(MRT).
http://www.youtube.com/watch?v=PABxoWZB0YM
main.cpp@1:4e19f154ec21, 2013-10-14 (annotated)
- Committer:
- va009039
- Date:
- Mon Oct 14 03:59:30 2013 +0000
- Revision:
- 1:4e19f154ec21
- Parent:
- 0:f86c572491c3
first commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
va009039 | 1:4e19f154ec21 | 1 | #ifdef TARGET_LPC812 |
va009039 | 1:4e19f154ec21 | 2 | #include "mbed.h" |
va009039 | 1:4e19f154ec21 | 3 | #include "SCT_PWM.h" |
va009039 | 1:4e19f154ec21 | 4 | #include "MRT.h" |
va009039 | 1:4e19f154ec21 | 5 | |
va009039 | 1:4e19f154ec21 | 6 | SCT_PWM r (LED_RED, 0); |
va009039 | 1:4e19f154ec21 | 7 | SCT_PWM g (LED_GREEN, 1); |
va009039 | 1:4e19f154ec21 | 8 | SCT_PWM b (LED_BLUE, 2); |
va009039 | 1:4e19f154ec21 | 9 | |
va009039 | 1:4e19f154ec21 | 10 | int main() |
va009039 | 1:4e19f154ec21 | 11 | { |
va009039 | 1:4e19f154ec21 | 12 | MRT* mrt = new MRT(); |
va009039 | 1:4e19f154ec21 | 13 | r.period(0.001); |
va009039 | 1:4e19f154ec21 | 14 | while(1) { |
va009039 | 1:4e19f154ec21 | 15 | for(float i = 0.0; i < 1.0 ; i += 0.001) { |
va009039 | 1:4e19f154ec21 | 16 | float p = 3 * i; |
va009039 | 1:4e19f154ec21 | 17 | r = 1.0 - ((p < 1.0) ? 1.0 - p : (p > 2.0) ? p - 2.0 : 0.0); |
va009039 | 1:4e19f154ec21 | 18 | g = 1.0 - ((p < 1.0) ? p : (p > 2.0) ? 0.0 : 2.0 - p); |
va009039 | 1:4e19f154ec21 | 19 | b = 1.0 - ((p < 1.0) ? 0.0 : (p > 2.0) ? 3.0 - p : p - 1.0); ; |
va009039 | 1:4e19f154ec21 | 20 | mrt->wait_ms(10); |
va009039 | 1:4e19f154ec21 | 21 | } |
va009039 | 1:4e19f154ec21 | 22 | } |
va009039 | 1:4e19f154ec21 | 23 | } |
va009039 | 1:4e19f154ec21 | 24 | |
va009039 | 1:4e19f154ec21 | 25 | #else |
va009039 | 1:4e19f154ec21 | 26 | // http://mbed.org/users/chris/code/app-board-RGB/ |
chris | 0:f86c572491c3 | 27 | #include "mbed.h" |
chris | 0:f86c572491c3 | 28 | |
chris | 0:f86c572491c3 | 29 | PwmOut r (p23); |
chris | 0:f86c572491c3 | 30 | PwmOut g (p24); |
chris | 0:f86c572491c3 | 31 | PwmOut b (p25); |
chris | 0:f86c572491c3 | 32 | |
chris | 0:f86c572491c3 | 33 | int main() |
chris | 0:f86c572491c3 | 34 | { |
chris | 0:f86c572491c3 | 35 | r.period(0.001); |
chris | 0:f86c572491c3 | 36 | while(1) { |
chris | 0:f86c572491c3 | 37 | for(float i = 0.0; i < 1.0 ; i += 0.001) { |
chris | 0:f86c572491c3 | 38 | float p = 3 * i; |
chris | 0:f86c572491c3 | 39 | r = 1.0 - ((p < 1.0) ? 1.0 - p : (p > 2.0) ? p - 2.0 : 0.0); |
chris | 0:f86c572491c3 | 40 | g = 1.0 - ((p < 1.0) ? p : (p > 2.0) ? 0.0 : 2.0 - p); |
chris | 0:f86c572491c3 | 41 | b = 1.0 - ((p < 1.0) ? 0.0 : (p > 2.0) ? 3.0 - p : p - 1.0); ; |
chris | 0:f86c572491c3 | 42 | wait (0.01); |
chris | 0:f86c572491c3 | 43 | } |
chris | 0:f86c572491c3 | 44 | } |
va009039 | 1:4e19f154ec21 | 45 | } |
va009039 | 1:4e19f154ec21 | 46 | #endif |