Anupam Goli
/
YWColorSensor
Color Sensor
Diff: main.cpp
- Revision:
- 0:0782f9fcaeb9
- Child:
- 1:3b9101b6ec3f
diff -r 000000000000 -r 0782f9fcaeb9 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Oct 23 15:20:30 2015 +0000 @@ -0,0 +1,151 @@ +#include "mbed.h" +#include "color.h" + +Serial pc(USBTX, USBRX); + +int flag=0; +int counter=0; +int countR=0,countG=0,countB=0; + +InterruptIn ctr(p25); +Ticker t; +int i = 0; +DigitalOut s0(p21); +DigitalOut s1(p22); +DigitalOut s2(p23); +DigitalOut s3(p24); +void count() +{ + + counter++; +} +void asd() +{ +flag++; + if(flag == 1) + { + countR = counter; + s2.write(1); + s3.write(1); + } + else if(flag == 2) + { + countG = counter; + s2.write(0); + s3.write(1); + } + else if(flag ==3) + { + countB = counter; + s2.write(0); + s3.write(0); + } + else if(flag == 4) + { + flag = 0; + } + counter = 0; + +} +int main() { + //s0.write(1); + //s1.write(1); + ColorSensor cs(p21, p22, p23, p24, p25); + while(1) + { + + //ctr.rise(&count); + //cs.getReading(); + //cs.poll(); + //ctr.rise(count); + //t.attach(&asd, .01); + //t.attach(&cs, &ColorSensor::poll, .01); + //ctr.rise(&cs, &ColorSensor::incCount); + pc.printf("r: %d", cs.getGreen()); + //pc.printf("interrupted! %d", cs.interrupted); + wait(0.01); + //counter = 0; + } + +} + +/* +int s0=3,s1=4,s2=5,s3=6; +int out=2; +int flag=0; +byte counter=0; +byte countR=0,countG=0,countB=0; +void setup() + { + Serial.begin(115200); + pinMode(s0,OUTPUT); + pinMode(s1,OUTPUT); + pinMode(s2,OUTPUT); + pinMode(s3,OUTPUT); + + } +void TCS() + { + flag=0; + digitalWrite(s1,HIGH); + digitalWrite(s0,HIGH); + digitalWrite(s2,LOW); + digitalWrite(s3,LOW); + attachInterrupt(0, ISR_INTO, CHANGE); + timer0_init(); + + } +void ISR_INTO() + { + counter++; + } + void timer0_init(void) + { + TCCR2A=0x00; + TCCR2B=0x07; //the clock frequency source 1024 points + TCNT2= 100; //10 ms overflow again + TIMSK2 = 0x01; //allow interrupt + } + int i=0; + ISR(TIMER2_OVF_vect)//the timer 2, 10ms interrupt overflow again. Internal overflow interrupt executive function +{ + TCNT2=100; + flag++; + if(flag==1) + { + countR=counter; + Serial.print("red="); + Serial.println(countR,DEC); + digitalWrite(s2,HIGH); + digitalWrite(s3,HIGH); + } + else if(flag==2) + { + countG=counter; + Serial.print("green="); + Serial.println(countG,DEC); + digitalWrite(s2,LOW); + digitalWrite(s3,HIGH); + } + else if(flag==3) + { + countB=counter; + Serial.print("blue="); + Serial.println(countB,DEC); + Serial.println("\n"); + digitalWrite(s2,LOW); + digitalWrite(s3,LOW); + + } + else if(flag==4) + { + flag=0; + } + counter=0; +} +void loop() + { + TCS(); +while(1); + } + */ \ No newline at end of file