not sure on the if statement at the bottom

Dependencies:   ContinuousServo TCS3472_I2C Tach mbed

Fork of ES202_Final_ColorSensor by Thomas Larrea

color.cpp

Committer:
PlayaLarrea
Date:
2018-04-30
Revision:
2:b5a85ba07057
Parent:
1:1dd468e2ad40

File content as of revision 2:b5a85ba07057:

#include "mbed.h"
#include "ContinuousServo.h"
#include "Tach.h"
#include "TCS3472_I2C.h"

//InterruptIn hall_sensor(p21);
DigitalOut hallpwr(p22);
DigitalIn hall(p21);
BusOut flash(LED1, LED2, LED3, LED4);
TCS3472_I2C rgb_sensor(p9, p10);
ContinuousServo left(p23);                  //Set up left wheel driver
ContinuousServo right(p26);                 //Set up right wheel driver

int rgb_data[4];
float PWMbrightness = 1.0;
float LB = 0.0;
int x = 0.0;
 
//void mine() {
//    flash = 8.0;
//    wait(1.0);
//    flash = 0;
//}
 
int main() {
    
    hall.mode(PullUp);
//    hall_sensor.rise(&mine);
//    hall_sensor.fall(&mine);
    hallpwr = 1;
    
    rgb_sensor.enablePowerAndRGBC();
    rgb_sensor.setIntegrationTime(100);
    
    while(1) {           // wait around, interrupts will interrupt this!
        
        x = hall.read();
        
        if(x == 1){
            flash = 8.0;
            }
        else{
            flash = 0.0;
            }
        x = hall.read();   
            
        left.speed(0.1);                     //Move the left wheel
        right.speed(-0.1);                    //Move the right wheel
        
        LB = PWMbrightness;
        rgb_sensor.getAllColors(rgb_data);
              
        //if(rgb_data[1]>650){
        if(rgb_data[0]>1000 && rgb_data[1]>650 && rgb_data[2]<300 && rgb_data[3]<300){
        flash = 1.0; //red
        }
        //else if(rgb_data[2]>650){
        else if(rgb_data[0]>900 && rgb_data[1]<700 && rgb_data[2]>650 && rgb_data[3]<700){
            flash = 2.0; //green
            }
            //else if(rgb_data[3]>300){
            else if(rgb_data[0]>900 && rgb_data[1]<300 && rgb_data[2]<300 && rgb_data[3]>300){
                flash = 4.0; //blue
                }
    }
}