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
- Committer:
- ksaito
- Date:
- 2018-03-14
- Revision:
- 5:614e3ac042df
- Parent:
- 4:d61f6d186db0
- Child:
- 7:8b0019dd26d3
File content as of revision 5:614e3ac042df:
#include "mbed.h"
#include "commands.h"
PwmOut r (p23);
PwmOut g (p24);
PwmOut b (p25);
static void _Finalize(void) {
r = 1.0;
g = 1.0;
b = 1.0;
r.period(0.000);
}
static void _Initialize(void) {
_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;
}
COMMAND_DEFINE Command_color = {"color", 0x04, _Initialize, _Finalize,
_ProcessInitialize, _ProcessIsContinue, _ProcessRunning
};