PMK_industrija_mikro4
Dependencies: rohm-rpr0521 rohm-sensor-hal Servo TextLCD
color.cpp
- Committer:
- emilija
- Date:
- 2021-07-05
- Revision:
- 1:c49ad58c141d
- Parent:
- 0:c4a5143aeebc
File content as of revision 1:c49ad58c141d:
#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();
}