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

Revision:
27:47a7bc902587
Parent:
24:8868101d01d0
Child:
28:bdf2bf56f97b
--- a/main.cpp	Thu Dec 04 12:31:23 2014 +0000
+++ b/main.cpp	Thu Dec 04 22:05:18 2014 +0000
@@ -1,6 +1,5 @@
 bool operationMode      = true; //the MBED starts in operation mode.
 
-
 #include "mbed.h"
 Serial pc(USBTX, USBRX);
 Serial glcd(p13, p14);
@@ -54,6 +53,9 @@
     if(buttonPressed(3)) {
         mode = !mode;
     }
+    /* NOTICE: Enable the modes below for more maintenace functions, good for debugging.
+     */
+
 
     /*
         if(mode == 0) {                                    //Dispense Mode
@@ -223,18 +225,20 @@
     }
 
 }
-
+//Coordinate changing language on PC and Arduino.
 void changeLanguage()
 {
     currentLanguage = nextLanguage(currentLanguage);        //Change the language on teh MBED.
-    sendLanguageCharacter();                                //Tell PC to change language
-    //Change Language                                       //Tell Arduino to change language.
+    sendLanguageCharacter();                                //Tell PC & Arduino to change language.
     wait(1);
 }
 
-
+/* void sortFunction()
+ *  Read sensor and sort according to the colour.
+ */
 void sortFunction()
 {
+    //Read the colour twice and make sure both are the same. If not then return and try again.
     Thread::wait(100);
     Colour colour = readColourSensor();
     Thread::wait(100);
@@ -242,6 +246,7 @@
     if(colour != colour2) {
         return;
     }
+    //Ensure a bin read is valid by ensuring it is the same as earlier. Prevents a bin read being valid if the chip is out of place on the sensor.
     if(colour == BIN) {
         Thread::wait(100);
         Colour binCheck = readColourSensor();
@@ -250,12 +255,6 @@
         }
     }
 
-    /* Tries to prevent a colour mis-read. When a chip is read as NONE,
-    the chip may be falling down the tube as the reading was taken. The chip may
-    also be out of position on the slider. Ignoring the next reading is trying to
-    prevent a mis-read being valid.*/
-
-
     //log("Sorting colour");
     sort(colour);
 }
@@ -310,10 +309,10 @@
                 //If not then do not dispense
                 pc.putc('<');
                 pcReady = false;
-            } else if(red ==0 && green == 0 && blue ==0){
+            } else if(red ==0 && green == 0 && blue ==0) {
                 pc.putc('@');
                 pcReady = false;
-             }else {
+            } else {
                 //Otherwise there are enough tokens so dispense the order
                 pc.putc('>');
 
@@ -373,15 +372,15 @@
     sendLanguageCharacter();
 
     Thread sortThread(sortMode);
-if(!languageButton){
-    operationMode = true;
-    mode = 0;
-    
-}else{
-    operationMode = false;
-    mode = 1;
+    if(!languageButton) {
+        operationMode = true;
+        mode = 0;
+
+    } else {
+        operationMode = false;
+        mode = 1;
     }
-Thread dispenseThread(dispenseMode);
+    Thread dispenseThread(dispenseMode);
     while(true) {
         led1 = 1;
         led4 = cardDetect;
@@ -395,11 +394,3 @@
         Thread::wait(100);
     }
 }
-
-
-
-
-
-
-
-