![](/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
colourProcessing.h@23:f9e7e64784be, 2014-11-29 (annotated)
- Committer:
- IonSystems
- Date:
- Sat Nov 29 16:32:57 2014 +0000
- Revision:
- 23:f9e7e64784be
- Parent:
- 22:8f11d1c178ab
- Child:
- 24:8868101d01d0
might be working
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
IonSystems | 6:e64796f1f384 | 1 | #include "mbed.h" |
IonSystems | 6:e64796f1f384 | 2 | #include "TCS3472_I2C.h" |
IonSystems | 6:e64796f1f384 | 3 | #include "Colour.h" |
IonSystems | 11:06f6e82b40a8 | 4 | |
IonSystems | 6:e64796f1f384 | 5 | TCS3472_I2C rgb_sensor(p28,p27); //p28 =sda, p27=scl |
IonSystems | 6:e64796f1f384 | 6 | |
IonSystems | 23:f9e7e64784be | 7 | int rgb_readings[10][4]; |
IonSystems | 14:31ba3e56c788 | 8 | int rgb_average[4] = {0,0,0,0}; |
IonSystems | 6:e64796f1f384 | 9 | double rMax = 9244; |
IonSystems | 6:e64796f1f384 | 10 | double gMax = 3194; |
IonSystems | 6:e64796f1f384 | 11 | double bMax = 3590; |
IonSystems | 23:f9e7e64784be | 12 | int tubeSize = 10; |
IonSystems | 23:f9e7e64784be | 13 | |
IonSystems | 17:6a0bb0ad5bb4 | 14 | int redLT [3] = {308,84,162}; |
IonSystems | 22:8f11d1c178ab | 15 | int redUT [3]= {400,144,204}; |
IonSystems | 17:6a0bb0ad5bb4 | 16 | int greenLT [3] = {91,180,142}; |
IonSystems | 17:6a0bb0ad5bb4 | 17 | int greenUT [3]= {132,220,184}; |
IonSystems | 17:6a0bb0ad5bb4 | 18 | int blueLT [3]= {79,95,117}; |
IonSystems | 17:6a0bb0ad5bb4 | 19 | int blueUT [3]= {117,139,157}; |
IonSystems | 13:0661d658d9d1 | 20 | int noneLT [3] = {0,0,0}; |
IonSystems | 13:0661d658d9d1 | 21 | int noneUT [3] = {80,80,80}; |
IonSystems | 6:e64796f1f384 | 22 | |
IonSystems | 23:f9e7e64784be | 23 | void initColourSensor() |
IonSystems | 23:f9e7e64784be | 24 | { |
IonSystems | 6:e64796f1f384 | 25 | rgb_sensor.enablePowerAndRGBC(); |
IonSystems | 6:e64796f1f384 | 26 | rgb_sensor.setIntegrationTime(100); |
IonSystems | 6:e64796f1f384 | 27 | } |
IonSystems | 6:e64796f1f384 | 28 | |
IonSystems | 23:f9e7e64784be | 29 | Colour readColourSensor() |
IonSystems | 23:f9e7e64784be | 30 | { |
IonSystems | 23:f9e7e64784be | 31 | for(int i = 0; i < 10; i++) { |
IonSystems | 23:f9e7e64784be | 32 | rgb_sensor.getAllColors(rgb_readings[i]); |
IonSystems | 23:f9e7e64784be | 33 | wait(0.001); |
IonSystems | 23:f9e7e64784be | 34 | } |
IonSystems | 23:f9e7e64784be | 35 | for(int i = 0; i < 10; i++) { |
IonSystems | 23:f9e7e64784be | 36 | for(int j = 0; j < 4; j++) { |
IonSystems | 23:f9e7e64784be | 37 | rgb_average[j] += rgb_readings[i][j]; |
IonSystems | 5:644bca33c1ca | 38 | } |
IonSystems | 23:f9e7e64784be | 39 | } |
IonSystems | 23:f9e7e64784be | 40 | for(int i = 0; i < 4; i++) { |
IonSystems | 23:f9e7e64784be | 41 | rgb_average[i] = rgb_average[i] / 10; |
IonSystems | 23:f9e7e64784be | 42 | } |
IonSystems | 23:f9e7e64784be | 43 | double redd = (rgb_average[1] /gMax) * 255; |
IonSystems | 23:f9e7e64784be | 44 | double greend = (rgb_average[2] /bMax) * 255; |
IonSystems | 23:f9e7e64784be | 45 | double blued = (rgb_average[0] /rMax) * 255; |
IonSystems | 23:f9e7e64784be | 46 | |
IonSystems | 23:f9e7e64784be | 47 | int red = redd; |
IonSystems | 23:f9e7e64784be | 48 | int green = greend; |
IonSystems | 23:f9e7e64784be | 49 | int blue = blued; |
IonSystems | 23:f9e7e64784be | 50 | |
IonSystems | 23:f9e7e64784be | 51 | bool redWithinThreshold[4] = {0,0,0,0}; |
IonSystems | 23:f9e7e64784be | 52 | bool greenWithinThreshold[4]= {0,0,0,0}; |
IonSystems | 23:f9e7e64784be | 53 | bool blueWithinThreshold[4]= {0,0,0,0}; |
IonSystems | 23:f9e7e64784be | 54 | //Set red Thresholds |
IonSystems | 23:f9e7e64784be | 55 | redWithinThreshold[0] = (red >= redLT[0]) && (red <= redUT[0]); |
IonSystems | 23:f9e7e64784be | 56 | greenWithinThreshold[0] = (green >= redLT[1]) && (green <= redUT[1]); |
IonSystems | 23:f9e7e64784be | 57 | blueWithinThreshold[0] = (blue >= redLT[2]) && (blue <= redUT[2]); |
IonSystems | 23:f9e7e64784be | 58 | //Set green Thresholds |
IonSystems | 23:f9e7e64784be | 59 | redWithinThreshold[1] = (red >= greenLT[0]) && (red <= greenUT[0]); |
IonSystems | 23:f9e7e64784be | 60 | greenWithinThreshold[1] = (green >= greenLT[1]) && (green <= greenUT[1]); |
IonSystems | 23:f9e7e64784be | 61 | blueWithinThreshold[1] = (blue >= greenLT[2]) && (blue <= greenUT[2]); |
IonSystems | 23:f9e7e64784be | 62 | //Set blue Thresholds |
IonSystems | 23:f9e7e64784be | 63 | redWithinThreshold[2] = (red >= blueLT[0]) && (red <= blueUT[0]); |
IonSystems | 23:f9e7e64784be | 64 | greenWithinThreshold[2] = (green >= blueLT[1]) && (green <= blueUT[1]); |
IonSystems | 23:f9e7e64784be | 65 | blueWithinThreshold[2] = blue >= blueLT[2] && blue <= blueUT[2]; |
IonSystems | 23:f9e7e64784be | 66 | //Set none Thresholds |
IonSystems | 23:f9e7e64784be | 67 | redWithinThreshold[3] = (red >= noneLT[0]) && (red <= noneUT[0]); |
IonSystems | 23:f9e7e64784be | 68 | greenWithinThreshold[3] = (green >= noneLT[1]) && (green <= noneUT[1]); |
IonSystems | 23:f9e7e64784be | 69 | blueWithinThreshold[3] = blue >= noneLT[2] && blue <= noneUT[2]; |
IonSystems | 23:f9e7e64784be | 70 | |
IonSystems | 23:f9e7e64784be | 71 | if(redWithinThreshold[0] && greenWithinThreshold[0] && blueWithinThreshold[0]) { |
IonSystems | 23:f9e7e64784be | 72 | return RED; |
IonSystems | 23:f9e7e64784be | 73 | } else if(redWithinThreshold[1] && greenWithinThreshold[1] && blueWithinThreshold[1]) { |
IonSystems | 23:f9e7e64784be | 74 | return GREEN; |
IonSystems | 23:f9e7e64784be | 75 | } else if(redWithinThreshold[2] && greenWithinThreshold[2] && blueWithinThreshold[2]) { |
IonSystems | 23:f9e7e64784be | 76 | return BLUE; |
IonSystems | 23:f9e7e64784be | 77 | } else if(redWithinThreshold[3] && greenWithinThreshold[3] && blueWithinThreshold[3]) { |
IonSystems | 23:f9e7e64784be | 78 | return NONE; |
IonSystems | 23:f9e7e64784be | 79 | } else { |
IonSystems | 23:f9e7e64784be | 80 | return BIN; |
IonSystems | 23:f9e7e64784be | 81 | } |
IonSystems | 23:f9e7e64784be | 82 | |
IonSystems | 5:644bca33c1ca | 83 | } |
IonSystems | 5:644bca33c1ca | 84 | |
IonSystems | 13:0661d658d9d1 | 85 | |
IonSystems | 23:f9e7e64784be | 86 |