PMKIND
Dependencies: rohm-rpr0521 rohm-sensor-hal Servo TextLCD
color.cpp
- Committer:
- pavledjo
- Date:
- 2021-06-27
- Revision:
- 1:7b52bdcdac4e
- Parent:
- 0:51001d8fdeff
File content as of revision 1:7b52bdcdac4e:
#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(); }