PMKIND
Dependencies: rohm-rpr0521 rohm-sensor-hal Servo TextLCD
color.cpp
00001 #include "mbed.h" 00002 #include "color.h" 00003 ColorSensor::ColorSensor(PinName ss0, PinName ss1, PinName ss2, PinName ss3, PinName sout): 00004 s0(ss0), s1(ss1), s2(ss2), s3(ss3), _out(sout) 00005 { 00006 s0.write(1); 00007 s1.write(1); 00008 s2.write(0); 00009 s3.write(0); 00010 interrupted = 12345; 00011 countR = counter; 00012 countG = counter; 00013 countB = counter; 00014 counter = 0; 00015 flag = 0; 00016 _out.mode(PullUp); 00017 _out.rise(this, &ColorSensor::incCount); 00018 ts.attach(this, &ColorSensor::getReading, .01); 00019 00020 } 00021 00022 int ColorSensor::getRed() 00023 { 00024 return countR; 00025 } 00026 int ColorSensor::getBlue() 00027 { 00028 return countB; 00029 } 00030 int ColorSensor::getGreen() 00031 { 00032 return countG; 00033 } 00034 void ColorSensor::incCount() 00035 { 00036 counter++; 00037 } 00038 void ColorSensor::getReading() 00039 { 00040 00041 flag++; 00042 if(flag == 1) 00043 { 00044 countR = counter; 00045 s2.write(1); 00046 s3.write(1); 00047 } 00048 else if(flag == 2) 00049 { 00050 countG = counter; 00051 s2.write(0); 00052 s3.write(1); 00053 } 00054 else if(flag ==3) 00055 { 00056 countB = counter; 00057 s2.write(0); 00058 s3.write(0); 00059 } 00060 else if(flag == 4) 00061 { 00062 flag = 0; 00063 } 00064 counter = 0; 00065 00066 } 00067 00068 00069 void ColorSensor::poll() 00070 { 00071 00072 ColorSensor::getReading(); 00073 00074 } 00075 00076
Generated on Thu Jul 14 2022 06:17:50 by
1.7.2