Dependents:   nhk2018_throwing02 nhk_2018_undercarry_test08 nhk_2018_undercarry_test09 nhk_2018_undercarry_test10 ... more

Fork of TCS3200 by Grant Phillips

Revision:
2:78984c66a877
Parent:
1:40b638b93be8
diff -r 40b638b93be8 -r 78984c66a877 TCS3200.cpp
--- a/TCS3200.cpp	Thu Mar 22 13:10:24 2018 +0000
+++ b/TCS3200.cpp	Mon Mar 26 02:57:48 2018 +0000
@@ -3,38 +3,60 @@
  
  
 TCS3200::TCS3200(PinName S2, PinName S3, PinName OUT) : 
-mS2(S2), mS3(S3), signal(OUT) 
-{
+mS2(S2), mS3(S3), signal(OUT){
     signal.rise(this,&TCS3200::HighTrigger);
     signal.fall(this,&TCS3200::LowTrigger);
-}
- 
-long TCS3200::ReadRed() {
-    mS2=0;      
-    mS3=0;
-    wait(0.1);     //Delay to allow frequency to change for the set color
-    return(pulsewidth);
+    ticker.attach(this,&TCS3200::fliper,0.1);
+    coler = RED;
+    mS2 = 0.0;
+    mS3 = 0.0;
 }
 
-long TCS3200::ReadGreen() {
-    mS2=1;                    
-    mS3=1;
-    wait(0.1);     //Delay to allow frequency to change for the set color
-    return(pulsewidth);
+void TCS3200::fliper(){
+    switch(coler){
+        case RED:
+        red_pulsewidth = pulsewidth;
+        mS2 = 1.0;
+        mS3 = 1.0;
+        coler = GREEN;
+        break;
+        case GREEN:
+        green_pulsewidth = pulsewidth;
+        mS2 = 0.0;
+        mS3 = 1.0;
+        coler = BLUE;
+        break;
+        case BLUE:
+        blue_pulsewidth = pulsewidth;
+        mS2 = 1.0;
+        mS3 = 0.0;
+        coler = CLEAR;
+        break;
+        case CLEAR:
+        clear_pulsewidth = pulsewidth;
+        mS2 = 0.0;
+        mS3 = 0.0;
+        coler = RED;
+        break;
+        default:
+        break;
+    }
+}
+    
+long TCS3200::ReadRed(){
+    return(red_pulsewidth);
 }
 
-long TCS3200::ReadBlue() {
-    mS2=0;  
-    mS3=1;
-    wait(0.1);     //Delay to allow frequency to change for the set color
-    return(pulsewidth);
+long TCS3200::ReadGreen(){
+    return(green_pulsewidth);
 }
 
-long TCS3200::ReadClear() {
-    mS2=1;                    
-    mS3=0;
-    wait(0.1);     //Delay to allow frequency to change for the set color
-    return(pulsewidth);
+long TCS3200::ReadBlue(){
+    return(blue_pulsewidth);
+}
+
+long TCS3200::ReadClear(){
+    return(clear_pulsewidth);
 }
 
 void TCS3200::HighTrigger() {