Marek Vitula / color
Committer:
nxf46245
Date:
Thu Oct 04 12:08:10 2018 +0000
Revision:
0:b1fcfaea3d32
ccbcvb

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nxf46245 0:b1fcfaea3d32 1 #include "MyColor.h"
nxf46245 0:b1fcfaea3d32 2 #include "mbed.h"
nxf46245 0:b1fcfaea3d32 3
nxf46245 0:b1fcfaea3d32 4
nxf46245 0:b1fcfaea3d32 5 MyColor::MyColor(PinName red, PinName green, PinName blue) : _red(red), _green(green), _blue(blue){
nxf46245 0:b1fcfaea3d32 6 _red.period(0.001f);
nxf46245 0:b1fcfaea3d32 7 _green.period(0.001f);
nxf46245 0:b1fcfaea3d32 8 _blue.period(0.001f);
nxf46245 0:b1fcfaea3d32 9 }
nxf46245 0:b1fcfaea3d32 10
nxf46245 0:b1fcfaea3d32 11 void MyColor::write(float val) {
nxf46245 0:b1fcfaea3d32 12 for (; val < 1.0f ; val += 0.001f) {
nxf46245 0:b1fcfaea3d32 13 float p = 3 * val;
nxf46245 0:b1fcfaea3d32 14 _red = 1.0f - ((p < 1.0f) ? 1.0f - p : (p > 2.0f) ? p - 2.0f : 0.0f);
nxf46245 0:b1fcfaea3d32 15 _green = 1.0f - ((p < 1.0f) ? p : (p > 2.0f) ? 0.0f : 2.0f - p);
nxf46245 0:b1fcfaea3d32 16 _blue = 1.0 - ((p < 1.0) ? 0.0 : (p > 2.0) ? 3.0 - p : p - 1.0);
nxf46245 0:b1fcfaea3d32 17 wait (0.0025f);
nxf46245 0:b1fcfaea3d32 18 }
nxf46245 0:b1fcfaea3d32 19 }
nxf46245 0:b1fcfaea3d32 20
nxf46245 0:b1fcfaea3d32 21
nxf46245 0:b1fcfaea3d32 22 MyColor& MyColor::operator= (float f) {
nxf46245 0:b1fcfaea3d32 23 write(f);
nxf46245 0:b1fcfaea3d32 24 return *this;
nxf46245 0:b1fcfaea3d32 25 }