Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
sc.cpp
00001 #include "mbed.h" 00002 #include "scolor_TCS3200.h" 00003 00004 00005 scolor_TCS3200::scolor_TCS3200(PinName s0, PinName s1, PinName s2, PinName s3, PinName s_in) : 00006 _s0(s0), _s1(s1), _s2(s2), _s3(s3), _s_in(s_in) 00007 { 00008 SetMode(SCALE_100); 00009 00010 }; 00011 00012 00013 long scolor_TCS3200::ReadRed() { _s2=0; _s3=0; return pulsewidth();} 00014 long scolor_TCS3200::ReadBlue() { _s2=0; _s3=1; return pulsewidth();} 00015 long scolor_TCS3200::ReadClear() { _s2=1; _s3=0; return pulsewidth();} 00016 long scolor_TCS3200::ReadGreen() { _s2=1; _s3=1; return pulsewidth();} 00017 00018 void scolor_TCS3200::SetMode(uint8_t mode) { 00019 switch (mode){ 00020 case SCALE_100: _s0= 1; _s1=1; break; 00021 case SCALE_20: _s0=1 ; _s1=0; break; 00022 case SCALE_2: _s0=0 ; _s1=1; break; 00023 case POWER_DOWN: _s0=0 ; _s1=0; break; 00024 } 00025 }; 00026 00027 long scolor_TCS3200::pulsewidth() { 00028 while(!_s_in); 00029 timer.start(); 00030 while(_s_in); 00031 timer.stop(); 00032 float pulsewidth_v = timer.read_us(); 00033 timer.reset(); 00034 return pulsewidth_v; 00035 }; 00036
Generated on Tue Aug 2 2022 10:12:38 by
1.7.2