Initial attempt at the final chalenge
Dependencies: ContinuousServo TCS3472_I2C Tach mbed
main.cpp
- Committer:
- m202346
- Date:
- 2018-04-26
- Revision:
- 1:d57be3c5dae9
- Parent:
- 0:10faa982ae23
File content as of revision 1:d57be3c5dae9:
#include "mbed.h" #include "ContinuousServo.h" #include "Tach.h" #include "TCS3472_I2C.h" //driving Tach tLeft(p17,64); Tach tRight(p13,64); ContinuousServo left(p23); ContinuousServo right(p26); //Color sensor PwmOut LB(p25); // PWM out signal to power LED on the sensor TCS3472_I2C rgb_sensor( p9, p10 ); // Establish RGB sensor object Serial pc(USBTX,USBRX); // Establish serial connection with computer //Hall effect InterruptIn hall(p21); DigitalOut led4(LED4); DigitalOut toggle(p22); int counter = 0; //need distance to stop float distance; distance = //inches; distance = //conversion to analog value; int main() { //Hall Effect hall.mode(PullUp); toggle = 1; led4 = 0; //Color sensor rgb_sensor.enablePowerAndRGBC(); // Enable RGB sensor rgb_sensor.setIntegrationTime(100); // Set integration time of sensor int rgb_data[4]; // declare a 4 element array to store RGB sensor readings float PWMbrightness = 1.0; // float specifying brightness of LED (between 0.0 and 1.0) while(1) { LB = PWMbrightness; // set brightness of sensor LED rgb_sensor.getAllColors( rgb_data ); // read the sensor to get red, green, and blue color data along with overall brightness if(hall == 1){ led4 = 1; wait(0.4); toggle = 0; wait(0.1); toggle = 1; led4 = 0; counter = counter +1; printf("Counter=%d\n",counter); }//if hall if (sonar > distance){ float speed = 0.5; left.speed(speed); right.speed(-speed); if (rgb_data[] > ){//add value for too dark right.speed(-speed - 0.05); left.speed(speed - 0.05); }//if dark else if (rgb_data[] <){//add value for too light right.speed(-speed + 0.05); left.speed(speed + 0.05); }//elseif light pc.printf( "unfiltered: %d, red: %d, green: %d, blue: %d \n", rgb_data[0], rgb_data[1], rgb_data[2], rgb_data[3]); wait(0.05); }//if sonar else { break; }//break }//while(1) }//int(main)