Dependents: nhk2018_throwing02 nhk_2018_undercarry_test08 nhk_2018_undercarry_test09 nhk_2018_undercarry_test10 ... more
Fork of TCS3200 by
TCS3200.cpp@0:b98e768bc655, 2016-05-03 (annotated)
- Committer:
- grantphillips
- Date:
- Tue May 03 20:45:40 2016 +0000
- Revision:
- 0:b98e768bc655
- Child:
- 1:40b638b93be8
v1.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
grantphillips | 0:b98e768bc655 | 1 | #include "TCS3200.h" |
grantphillips | 0:b98e768bc655 | 2 | #include "mbed.h" |
grantphillips | 0:b98e768bc655 | 3 | |
grantphillips | 0:b98e768bc655 | 4 | |
grantphillips | 0:b98e768bc655 | 5 | TCS3200::TCS3200(PinName S0, PinName S1, PinName S2, PinName S3, PinName OUT) : |
grantphillips | 0:b98e768bc655 | 6 | mS0(S0), mS1(S1), mS2(S2), mS3(S3), signal(OUT) |
grantphillips | 0:b98e768bc655 | 7 | { |
grantphillips | 0:b98e768bc655 | 8 | SetMode(SCALE_100); |
grantphillips | 0:b98e768bc655 | 9 | signal.rise(this,&TCS3200::HighTrigger); |
grantphillips | 0:b98e768bc655 | 10 | signal.fall(this,&TCS3200::LowTrigger); |
grantphillips | 0:b98e768bc655 | 11 | } |
grantphillips | 0:b98e768bc655 | 12 | |
grantphillips | 0:b98e768bc655 | 13 | long TCS3200::ReadRed() { |
grantphillips | 0:b98e768bc655 | 14 | mS2=0; |
grantphillips | 0:b98e768bc655 | 15 | mS3=0; |
grantphillips | 0:b98e768bc655 | 16 | wait(0.1); //Delay to allow frequency to change for the set color |
grantphillips | 0:b98e768bc655 | 17 | return(pulsewidth); |
grantphillips | 0:b98e768bc655 | 18 | } |
grantphillips | 0:b98e768bc655 | 19 | |
grantphillips | 0:b98e768bc655 | 20 | long TCS3200::ReadGreen() { |
grantphillips | 0:b98e768bc655 | 21 | mS2=1; |
grantphillips | 0:b98e768bc655 | 22 | mS3=1; |
grantphillips | 0:b98e768bc655 | 23 | wait(0.1); //Delay to allow frequency to change for the set color |
grantphillips | 0:b98e768bc655 | 24 | return(pulsewidth); |
grantphillips | 0:b98e768bc655 | 25 | } |
grantphillips | 0:b98e768bc655 | 26 | |
grantphillips | 0:b98e768bc655 | 27 | long TCS3200::ReadBlue() { |
grantphillips | 0:b98e768bc655 | 28 | mS2=0; |
grantphillips | 0:b98e768bc655 | 29 | mS3=1; |
grantphillips | 0:b98e768bc655 | 30 | wait(0.1); //Delay to allow frequency to change for the set color |
grantphillips | 0:b98e768bc655 | 31 | return(pulsewidth); |
grantphillips | 0:b98e768bc655 | 32 | } |
grantphillips | 0:b98e768bc655 | 33 | |
grantphillips | 0:b98e768bc655 | 34 | long TCS3200::ReadClear() { |
grantphillips | 0:b98e768bc655 | 35 | mS2=1; |
grantphillips | 0:b98e768bc655 | 36 | mS3=0; |
grantphillips | 0:b98e768bc655 | 37 | wait(0.1); //Delay to allow frequency to change for the set color |
grantphillips | 0:b98e768bc655 | 38 | return(pulsewidth); |
grantphillips | 0:b98e768bc655 | 39 | } |
grantphillips | 0:b98e768bc655 | 40 | |
grantphillips | 0:b98e768bc655 | 41 | void TCS3200::SetMode(TCS3200Mode mode) { |
grantphillips | 0:b98e768bc655 | 42 | if(mode == POWERDOWN) { //TCS3200 in power down |
grantphillips | 0:b98e768bc655 | 43 | mS0 = 0; |
grantphillips | 0:b98e768bc655 | 44 | mS1 = 0; |
grantphillips | 0:b98e768bc655 | 45 | } |
grantphillips | 0:b98e768bc655 | 46 | else if(mode == SCALE_2) { //Output frequency at 2% scaling |
grantphillips | 0:b98e768bc655 | 47 | mS0 = 0; |
grantphillips | 0:b98e768bc655 | 48 | mS1 = 1; |
grantphillips | 0:b98e768bc655 | 49 | } |
grantphillips | 0:b98e768bc655 | 50 | else if(mode == SCALE_20) { //Output frequency at 20% scaling |
grantphillips | 0:b98e768bc655 | 51 | mS0 = 1; |
grantphillips | 0:b98e768bc655 | 52 | mS1 = 0; |
grantphillips | 0:b98e768bc655 | 53 | } |
grantphillips | 0:b98e768bc655 | 54 | else if(mode == SCALE_100) { //Output frequency at 100% scaling |
grantphillips | 0:b98e768bc655 | 55 | mS0 = 1; |
grantphillips | 0:b98e768bc655 | 56 | mS1 = 1; |
grantphillips | 0:b98e768bc655 | 57 | } |
grantphillips | 0:b98e768bc655 | 58 | else { //default is POWERDOWN |
grantphillips | 0:b98e768bc655 | 59 | mS0 = 0; |
grantphillips | 0:b98e768bc655 | 60 | mS1 = 0; |
grantphillips | 0:b98e768bc655 | 61 | } |
grantphillips | 0:b98e768bc655 | 62 | } |
grantphillips | 0:b98e768bc655 | 63 | |
grantphillips | 0:b98e768bc655 | 64 | void TCS3200::HighTrigger() { |
grantphillips | 0:b98e768bc655 | 65 | timer.start(); |
grantphillips | 0:b98e768bc655 | 66 | } |
grantphillips | 0:b98e768bc655 | 67 | |
grantphillips | 0:b98e768bc655 | 68 | void TCS3200::LowTrigger() { |
grantphillips | 0:b98e768bc655 | 69 | timer.stop(); |
grantphillips | 0:b98e768bc655 | 70 | pulsewidth = timer.read_us(); |
grantphillips | 0:b98e768bc655 | 71 | timer.reset(); |
grantphillips | 0:b98e768bc655 | 72 | } |