preliminary code

Dependencies:   Motor TCS3472_I2C mbed

control.cpp

Committer:
ThatsAKnife
Date:
2015-04-26
Revision:
2:372ec56bb276
Parent:
1:789224bfa1e4

File content as of revision 2:372ec56bb276:

#include "mbed.h"
#include "Motor.h"
#include "TCS3472_I2C.h"

PwmOut brightness(p22);
TCS3472_I2C rgb(p28, p27);
Timer time;
AnalogIn photo1(p15);
AnalogIn photo2(p16);
AnalogIn photo3(p17);
AnalogIn photo4(p18);
AnalogIn photo5(p19);

int running=1;
int rgb_data[4];
float set_brightness = 1.0;
float left;
float right;
float center;

int main(){
    rgb.enablePowerAndRGBC();
    rgb.setIntegrationTime(100);
    brightness=set_brightness;
    time.start();
    //dc left fwd
    //dc rght fwd    
    while(running=1){
        rgb.getAllColors(rgb_data);
        if(rgb_data[1]>120 && rgb_data[2]<100){ //red;recalibrate
            while(rgb_data[1]>100){ //recalibrate
                //dc left rev
                //dc rght fwd
                time.reset();
                rgb.getAllColors(rgb_data);
            };
            //dc left fwd
            //dc rght fwd

        };
        if(rgb_data[2]>100){ //green;recalibrate
            while(rgb_data[2]>90){ //recalibrate
                //dc left fwd
                //dc rght rev
                time.reset();
                rgb.getAllColors(rgb_data);
            };
            //dc left fwd
            //dc rght fwd
        };
        if (time>5){ //arbitrary number-->fix later
            left=photo1+photo2;
            center=2*photo3;
            while(left>(center+0.01)){ //recalibrate
                //dc left rev
                //dc rght fwd
                left=photo1+photo2;
                center=2*photo3;
                right=photo4+photo5;
            };
            center=2*photo3;
            right=photo4+photo5;
            while(right>(center+0.01)){//recalibrate
                //dc left fwd
                //dc rght rev
                left=photo1+photo2;
                center=2*photo3;
                right=photo4+photo5;
            };
            //dc left fwd
            //dc rght fwd
            time.reset();
        };
        left=photo1+photo2;
        center=2*photo3;
        right=photo4+photo5;
        //collect sonar
        if (left<(center+0.01) && right<(center+0.01) && /* sonar is short */){ //recalibrate
            running=0;
            //dc left stop
            //dc rght stop
        };
    };
};