Class library for a TCS3200 Color Sensor Module.

Dependents:   LCD PROJETO PROJETO_MECATRONICO Bottle_Tracker_Insper ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers TCS3200.cpp Source File

TCS3200.cpp

00001 #include "TCS3200.h"
00002 #include "mbed.h"
00003  
00004  
00005 TCS3200::TCS3200(PinName S0, PinName S1, PinName S2, PinName S3, PinName OUT) : 
00006 mS0(S0), mS1(S1), mS2(S2), mS3(S3), signal(OUT) 
00007 {
00008     SetMode(SCALE_100);
00009     signal.rise(this,&TCS3200::HighTrigger);
00010     signal.fall(this,&TCS3200::LowTrigger);
00011 }
00012  
00013 long TCS3200::ReadRed() {
00014     mS2=0;                    
00015     mS3=0;
00016     wait(0.1);     //Delay to allow frequency to change for the set color
00017     return(pulsewidth);
00018 }
00019 
00020 long TCS3200::ReadGreen() {
00021     mS2=1;                    
00022     mS3=1;
00023     wait(0.1);     //Delay to allow frequency to change for the set color
00024     return(pulsewidth);
00025 }
00026 
00027 long TCS3200::ReadBlue() {
00028     mS2=0;                    
00029     mS3=1;
00030     wait(0.1);     //Delay to allow frequency to change for the set color
00031     return(pulsewidth);
00032 }
00033 
00034 long TCS3200::ReadClear() {
00035     mS2=1;                    
00036     mS3=0;
00037     wait(0.1);     //Delay to allow frequency to change for the set color
00038     return(pulsewidth);
00039 }
00040 
00041 void TCS3200::SetMode(TCS3200Mode mode) {
00042     if(mode == POWERDOWN) {         //TCS3200 in power down
00043         mS0 = 0;                     
00044         mS1 = 0;
00045     }
00046     else if(mode == SCALE_2) {      //Output frequency at 2% scaling
00047         mS0 = 0;                     
00048         mS1 = 1;
00049     }
00050     else if(mode == SCALE_20) {     //Output frequency at 20% scaling
00051         mS0 = 1;                     
00052         mS1 = 0;
00053     }
00054     else if(mode == SCALE_100) {    //Output frequency at 100% scaling
00055         mS0 = 1;                     
00056         mS1 = 1;
00057     }
00058     else {                          //default is POWERDOWN                
00059         mS0 = 0;                     
00060         mS1 = 0;
00061     }
00062 }
00063 
00064 void TCS3200::HighTrigger() {
00065     timer.start();
00066 }
00067 
00068 void TCS3200::LowTrigger() {
00069     timer.stop();
00070     pulsewidth = timer.read_us();
00071     timer.reset();
00072 }