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: C12832 MMA7660 mbed
color.cpp@1:2967eac08981, 2018-02-21 (annotated)
- Committer:
- ksaito
- Date:
- Wed Feb 21 09:13:28 2018 +0000
- Revision:
- 1:2967eac08981
- Parent:
- 0:c3bc6981ad28
- Child:
- 4:d61f6d186db0
?????????
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| ksaito | 0:c3bc6981ad28 | 1 | #include "mbed.h" |
| ksaito | 1:2967eac08981 | 2 | #include "commands.h" |
| ksaito | 0:c3bc6981ad28 | 3 | |
| ksaito | 0:c3bc6981ad28 | 4 | PwmOut r (p23); |
| ksaito | 0:c3bc6981ad28 | 5 | PwmOut g (p24); |
| ksaito | 0:c3bc6981ad28 | 6 | PwmOut b (p25); |
| ksaito | 0:c3bc6981ad28 | 7 | |
| ksaito | 1:2967eac08981 | 8 | static void _Finalize(void) { |
| ksaito | 1:2967eac08981 | 9 | r = 1.0; |
| ksaito | 1:2967eac08981 | 10 | g = 1.0; |
| ksaito | 1:2967eac08981 | 11 | b = 1.0; |
| ksaito | 0:c3bc6981ad28 | 12 | } |
| ksaito | 0:c3bc6981ad28 | 13 | |
| ksaito | 1:2967eac08981 | 14 | static void _Initialize(void) { |
| ksaito | 1:2967eac08981 | 15 | r.period(0.001); |
| ksaito | 1:2967eac08981 | 16 | _Finalize(); |
| ksaito | 1:2967eac08981 | 17 | } |
| ksaito | 1:2967eac08981 | 18 | |
| ksaito | 1:2967eac08981 | 19 | static void _Process(void) { |
| ksaito | 0:c3bc6981ad28 | 20 | for (float i = 0.0; i < 1.0 ; i += 0.001) { |
| ksaito | 0:c3bc6981ad28 | 21 | float p = 3 * i; |
| ksaito | 0:c3bc6981ad28 | 22 | r = 1.0 - ((p < 1.0) ? 1.0 - p : (p > 2.0) ? p - 2.0 : 0.0); |
| ksaito | 0:c3bc6981ad28 | 23 | g = 1.0 - ((p < 1.0) ? p : (p > 2.0) ? 0.0 : 2.0 - p); |
| ksaito | 0:c3bc6981ad28 | 24 | b = 1.0 - ((p < 1.0) ? 0.0 : (p > 2.0) ? 3.0 - p : p - 1.0); ; |
| ksaito | 0:c3bc6981ad28 | 25 | wait (0.01); |
| ksaito | 0:c3bc6981ad28 | 26 | } |
| ksaito | 0:c3bc6981ad28 | 27 | } |
| ksaito | 0:c3bc6981ad28 | 28 | |
| ksaito | 1:2967eac08981 | 29 | COMMAND_DEFINE Command_color = {"color", 0x04, _Initialize, _Finalize, _Process}; |