Module ColorDetection_EventChecker.c Description This is an event checker function for detecting if a ball crossed the color sensor and reads the color of the ball Notes Private definitions CategorizeColor CurrentColor LastColor NewBall ColorCounter LegalBall bool CheckNewBall(void) //Read Clear value from I2CService and store in ClearValue //Read Red value from I2CService and store in RedValue //Read Blue value from I2CService and store in BluValue //Read Green value from I2CService and store in GrnValue //Call CategorizeColor function, and store in CurrentColor //If ClearValue is greater than 4500, and CurrentColor is less than 7, and LegalBall is true //If ColorCounter is 100 //Get latest value of CompassColor from CompassService //Check if CurrentColor is equal to CompassColor or if CurrentColor is a blue ball //Recycling ball recieved, //Post BALL_AT_COLOR_SENSOR event to BallSortingService, with Param 1 //else //Landfill ball recieved //Post BALL_AT_COLOR_SENSOR event to BallSortingService, with Param 0 // Set LegalBall to false // Set ReturnVal to true //else //Increase ColorCounter by 1 //Else if ClearValue is less than 2000 //The ball has been sorted //Set ColorCounter to 0 //Set LegalBallt to true //return ReturnVal static uint8_t CategorizeColor(uint16_t Clr_Value, uint16_t Red_Value, uint16_t Blu_Value, uint16_t Grn_Value) //Calculate Red_Per by multiplying RedValue by 100 and dividing by ClearValue //Calculate Blu_Per by multiplying BluValue by 100 and dividing by ClearValue //Calculate Grn_Per by multiplying GrnValue by 100 and dividing by ClearValue //Check individual tresholds for each color from percentages //If Red_Per is between 51 and 65, Blu_Per between 12 and 18 and Grn_Per between 13 and 19 //Red ball detected //Set BallColor to 0 //printf("Red"); //If Red_Per is between 59 and 65, Blu_Per between 10 and 16 and Grn_Per between 18 and 24 //Orange ball detected //Set BallColor to 1 //If Red_Per is between 40 and 52, Blu_Per between 10 and 16 and Grn_Per between 30 and 40 //Yellow ball detected //Set BallColor to 2 //If Red_Per is between 30 and 36, Blu_Per between 14 and 20 and Grn_Per between 40 and 46 //Green ball detected //Set BallColor to 3 //If Red_Per is between 8 and 16, Blu_Per between 45 and 58 and Grn_Per between 29 and 35 //Blue ball detected //Set BallColor to 4 //If Red_Per is between 52 and 58, Blu_Per between 21 and 27 and Grn_Per between 17 and 23 //Pink ball detected //Set BallColor to 5 //else //No correct color detected, return trash byte //Set BallColor to 8 //return BallColor;