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
Diff: color.cpp
- Revision:
- 4:d61f6d186db0
- Parent:
- 1:2967eac08981
- Child:
- 5:614e3ac042df
--- a/color.cpp Wed Feb 21 09:25:48 2018 +0000
+++ b/color.cpp Wed Mar 07 10:57:16 2018 +0000
@@ -16,14 +16,32 @@
_Finalize();
}
+static float _ColorRange = 0.0;
+static void _ProcessInitialize(void) {
+ _ColorRange = 0.0;
+}
+
+static bool _ProcessIsContinue(void) {
+ return _ColorRange < 1.0;
+}
+
+static void _ProcessRunning(void) {
+ float p = 3 * _ColorRange;
+ r = 1.0 - ((p < 1.0) ? 1.0 - p : (p > 2.0) ? p - 2.0 : 0.0);
+ g = 1.0 - ((p < 1.0) ? p : (p > 2.0) ? 0.0 : 2.0 - p);
+ b = 1.0 - ((p < 1.0) ? 0.0 : (p > 2.0) ? 3.0 - p : p - 1.0); ;
+ wait (0.01);
+
+ _ColorRange += 0.001;
+}
+
static void _Process(void) {
- for (float i = 0.0; i < 1.0 ; i += 0.001) {
- float p = 3 * i;
- r = 1.0 - ((p < 1.0) ? 1.0 - p : (p > 2.0) ? p - 2.0 : 0.0);
- g = 1.0 - ((p < 1.0) ? p : (p > 2.0) ? 0.0 : 2.0 - p);
- b = 1.0 - ((p < 1.0) ? 0.0 : (p > 2.0) ? 3.0 - p : p - 1.0); ;
- wait (0.01);
+ _ProcessInitialize();
+ while ( _ProcessIsContinue() ) {
+ _ProcessRunning();
}
}
-COMMAND_DEFINE Command_color = {"color", 0x04, _Initialize, _Finalize, _Process};
+COMMAND_DEFINE Command_color = {"color", 0x04, _Initialize, _Finalize, _Process,
+ _ProcessInitialize, _ProcessIsContinue, _ProcessRunning
+};