![](/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: main.cpp
- Revision:
- 22:8f11d1c178ab
- Parent:
- 19:78d4b78fa736
- Child:
- 23:f9e7e64784be
--- a/main.cpp Tue Nov 25 13:48:23 2014 +0000 +++ b/main.cpp Tue Nov 25 22:32:26 2014 +0000 @@ -49,6 +49,7 @@ if(mode == 0){ //Dispense Mode printLCD("Dispense Mode"); + operationMode=false; if(buttonPressed(0)){ printLCD("Red Button pressed"); dispense(RED); @@ -61,6 +62,7 @@ } }else if(mode == 1){ //Sort Mode printLCD("Sort Mode"); + operationMode=false; if(buttonPressed(0)){ log("Red Button pressed"); sort(RED); @@ -74,19 +76,32 @@ }else if(mode == 2){ //Bin/Recycle Mode printLCD("Bin/Recycle Mode"); + operationMode=false; if(buttonPressed(0)){ log("Bin button pressed"); sort(BIN); }else if(buttonPressed(1)){ log("Recycle Button"); - sort(RECYCLE); + recycle(); } }else if(mode == 3){ printLCD("Colour Sensor Mode"); //Colour Sensing Mode if(colourSensor){ - - + operationMode=true; + wait(0.2); Colour colour = readColourSensor(); + Colour colour2 = readColourSensor(); + if(colour != colour2){ + return; + } + if(colour == BIN){ //Make tripley sure that it is actuall a bin chip + printLCD("BIN CHECK"); + wait(0.2); + Colour binCheck = readColourSensor(); + if(binCheck != colour){ + return; + } + } lastColour = colourStore; colourStore = colour; /* Tries to prevent a colour mis-read. When a chip is read as NONE, @@ -98,17 +113,19 @@ return; } - + //wait(5); if(sorter) sort(colour); //Put (sorter && colour != BIN) in if statement. } //if }else if(mode == 4){ //Card Reader Mode + operationMode= true; if(cardReader && cardDetect){ cardAcquisition(); } }else if(mode == 5){ //Storage Mode + operationMode=true; stringstream ss; ss << "Stored Values " << "R:" << redAmount << "G:" << greenAmount << "B:" << blueAmount; string tmp = ss.str(); @@ -132,18 +149,19 @@ } }else if(mode == 6){ + operationMode = false; stringstream ss; ss << maintenanceModeSelect; string mainModeSelect = ss.str(); - printLCD("Main. Mode: " + mainModeSelect); + printLCD("Maintenance: " + mainModeSelect); wait(0.1); //Maintenance Mode //printLCD("Maintenance Mode"); if(buttonPressed(0)){ //Next maintenance function maintenanceModeSelect++; - if(maintenanceModeSelect > 12) maintenanceModeSelect = 0; + if(maintenanceModeSelect > 13) maintenanceModeSelect = 0; }else if(buttonPressed(1)){ //Previous maintenance function maintenanceModeSelect--; - if(maintenanceModeSelect < 0) maintenanceModeSelect = 12; + if(maintenanceModeSelect < 0) maintenanceModeSelect = 13; }else if(buttonPressed(2)){ //Process Instruction switch(maintenanceModeSelect){ case 0://RB_LEFT: @@ -211,6 +229,10 @@ maintain(GB_RIGHT ); break; + case 13: //MaintenanceEND + printLCD("Ending Maintenance Mode"); + maintain(maintenanceEND); + break; } printLCD("Ready for next command");