Dependents: nhk2018_throwing02 nhk_2018_undercarry_test08 nhk_2018_undercarry_test09 nhk_2018_undercarry_test10 ... more
Fork of TCS3200 by
TCS3200.cpp@1:40b638b93be8, 2018-03-22 (annotated)
- Committer:
- kenken0721
- Date:
- Thu Mar 22 13:10:24 2018 +0000
- Revision:
- 1:40b638b93be8
- Parent:
- 0:b98e768bc655
- Child:
- 2:78984c66a877
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 | |
kenken0721 | 1:40b638b93be8 | 5 | TCS3200::TCS3200(PinName S2, PinName S3, PinName OUT) : |
kenken0721 | 1:40b638b93be8 | 6 | mS2(S2), mS3(S3), signal(OUT) |
grantphillips | 0:b98e768bc655 | 7 | { |
grantphillips | 0:b98e768bc655 | 8 | signal.rise(this,&TCS3200::HighTrigger); |
grantphillips | 0:b98e768bc655 | 9 | signal.fall(this,&TCS3200::LowTrigger); |
grantphillips | 0:b98e768bc655 | 10 | } |
grantphillips | 0:b98e768bc655 | 11 | |
grantphillips | 0:b98e768bc655 | 12 | long TCS3200::ReadRed() { |
kenken0721 | 1:40b638b93be8 | 13 | mS2=0; |
grantphillips | 0:b98e768bc655 | 14 | mS3=0; |
grantphillips | 0:b98e768bc655 | 15 | wait(0.1); //Delay to allow frequency to change for the set color |
grantphillips | 0:b98e768bc655 | 16 | return(pulsewidth); |
grantphillips | 0:b98e768bc655 | 17 | } |
grantphillips | 0:b98e768bc655 | 18 | |
grantphillips | 0:b98e768bc655 | 19 | long TCS3200::ReadGreen() { |
grantphillips | 0:b98e768bc655 | 20 | mS2=1; |
grantphillips | 0:b98e768bc655 | 21 | mS3=1; |
grantphillips | 0:b98e768bc655 | 22 | wait(0.1); //Delay to allow frequency to change for the set color |
grantphillips | 0:b98e768bc655 | 23 | return(pulsewidth); |
grantphillips | 0:b98e768bc655 | 24 | } |
grantphillips | 0:b98e768bc655 | 25 | |
grantphillips | 0:b98e768bc655 | 26 | long TCS3200::ReadBlue() { |
kenken0721 | 1:40b638b93be8 | 27 | mS2=0; |
grantphillips | 0:b98e768bc655 | 28 | mS3=1; |
grantphillips | 0:b98e768bc655 | 29 | wait(0.1); //Delay to allow frequency to change for the set color |
grantphillips | 0:b98e768bc655 | 30 | return(pulsewidth); |
grantphillips | 0:b98e768bc655 | 31 | } |
grantphillips | 0:b98e768bc655 | 32 | |
grantphillips | 0:b98e768bc655 | 33 | long TCS3200::ReadClear() { |
grantphillips | 0:b98e768bc655 | 34 | mS2=1; |
grantphillips | 0:b98e768bc655 | 35 | mS3=0; |
grantphillips | 0:b98e768bc655 | 36 | wait(0.1); //Delay to allow frequency to change for the set color |
grantphillips | 0:b98e768bc655 | 37 | return(pulsewidth); |
grantphillips | 0:b98e768bc655 | 38 | } |
grantphillips | 0:b98e768bc655 | 39 | |
grantphillips | 0:b98e768bc655 | 40 | void TCS3200::HighTrigger() { |
grantphillips | 0:b98e768bc655 | 41 | timer.start(); |
grantphillips | 0:b98e768bc655 | 42 | } |
grantphillips | 0:b98e768bc655 | 43 | |
grantphillips | 0:b98e768bc655 | 44 | void TCS3200::LowTrigger() { |
grantphillips | 0:b98e768bc655 | 45 | timer.stop(); |
grantphillips | 0:b98e768bc655 | 46 | pulsewidth = timer.read_us(); |
grantphillips | 0:b98e768bc655 | 47 | timer.reset(); |
grantphillips | 0:b98e768bc655 | 48 | } |