![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
The MBED firmware used on the Chipin sorter, developed over 12 weeks for a 3rd year university systems project. Chipin is a token sorter, it sorts tokens by colours and dispenses them to order through an online booking system and card reader. This program interfaces with an FPGA, PC and LCD screen to control the sorter. The sorter has an operation mode where it can process orders when a card is entered into the machine. There is also a maintenance mode where the device responds to maintenance instructions such as 'dispense all'. More information at http://www.ionsystems.uk/
Dependencies: MCP23017 TCS3472_I2C WattBob_TextLCD mbed-rtos mbed
Diff: colourProcessing.h
- Revision:
- 14:31ba3e56c788
- Parent:
- 13:0661d658d9d1
- Child:
- 15:0c5f20e15b6a
diff -r 0661d658d9d1 -r 31ba3e56c788 colourProcessing.h --- a/colourProcessing.h Thu Nov 20 11:15:47 2014 +0000 +++ b/colourProcessing.h Thu Nov 20 22:02:54 2014 +0000 @@ -4,7 +4,8 @@ TCS3472_I2C rgb_sensor(p28,p27); //p28 =sda, p27=scl -int rgb_readings[4]; +int rgb_readings[1000][4]; +int rgb_average[4] = {0,0,0,0}; double rMax = 9244; double gMax = 3194; double bMax = 3590; @@ -19,12 +20,12 @@ int blueLT [3]= {25,47,47}; int blueUT [3]= {28,52,52};*/ //values for blue backing -int redLT [3] = {300,80,150}; -int redUT [3]= {400,156,230}; -int greenLT [3] = {180,356,265}; -int greenUT [3]= {268,436,345}; -int blueLT [3]= {89,187,189}; -int blueUT [3]= {168,267,269}; +int redLT [3] = {280,50,50}; +int redUT [3]= {420,180,260}; +int greenLT [3] = {60,190,106}; +int greenUT [3]= {180,270,226}; +int blueLT [3]= {59,68,85}; +int blueUT [3]= {169,188,205}; int noneLT [3] = {0,0,0}; int noneUT [3] = {80,80,80}; @@ -34,11 +35,24 @@ } Colour readColourSensor(){ - rgb_sensor.getAllColors(rgb_readings); - - double redd = (rgb_readings[1] /gMax) * 255; - double greend = (rgb_readings[2] /bMax) * 255; - double blued = (rgb_readings[0] /rMax) * 255; + lcd->cls(); // clear display + lcd->locate(0,0); + lcd->printf("Reading Sensor"); + for(int i = 0; i < 1000; i++){ + rgb_sensor.getAllColors(rgb_readings[i]); + wait(0.0025); + } + for(int i = 0; i < 1000; i++){ + for(int j = 0; j < 4; j++){ + rgb_average[j] += rgb_readings[i][j]; + } + } + for(int i = 0; i < 4; i++){ + rgb_average[i] =rgb_average[i] / 1000; + } + double redd = (rgb_average[1] /gMax) * 255; + double greend = (rgb_average[2] /bMax) * 255; + double blued = (rgb_average[0] /rMax) * 255; int red = redd; int green = greend;