PMKIND
Dependencies: rohm-rpr0521 rohm-sensor-hal Servo TextLCD
Diff: color.cpp
- Revision:
- 0:51001d8fdeff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/color.cpp Thu Jun 24 15:11:30 2021 +0000 @@ -0,0 +1,76 @@ +#include "mbed.h" +#include "color.h" + ColorSensor::ColorSensor(PinName ss0, PinName ss1, PinName ss2, PinName ss3, PinName sout): + s0(ss0), s1(ss1), s2(ss2), s3(ss3), _out(sout) + { + s0.write(1); + s1.write(1); + s2.write(0); + s3.write(0); + interrupted = 12345; + countR = counter; + countG = counter; + countB = counter; + counter = 0; + flag = 0; + _out.mode(PullUp); + _out.rise(this, &ColorSensor::incCount); + ts.attach(this, &ColorSensor::getReading, .01); + + } + + int ColorSensor::getRed() + { + return countR; + } + int ColorSensor::getBlue() + { + return countB; + } + int ColorSensor::getGreen() + { + return countG; + } + void ColorSensor::incCount() + { + counter++; + } + void ColorSensor::getReading() + { + + flag++; + if(flag == 1) + { + countR = counter; + s2.write(1); + s3.write(1); + } + else if(flag == 2) + { + countG = counter; + s2.write(0); + s3.write(1); + } + else if(flag ==3) + { + countB = counter; + s2.write(0); + s3.write(0); + } + else if(flag == 4) + { + flag = 0; + } + counter = 0; + + } + + + void ColorSensor::poll() + { + + ColorSensor::getReading(); + + } + + \ No newline at end of file