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:
8:b7771391adc9
Parent:
7:6ba00694f9cd
Child:
9:8d78eb55ad5e
--- a/main.cpp	Mon Nov 10 15:03:20 2014 +0000
+++ b/main.cpp	Mon Nov 10 16:32:44 2014 +0000
@@ -5,6 +5,7 @@
 #include "rgbLED.h"
 #include "mbedLCD.h"
 #include "stateMachine.h"
+#include "FPGAcomms.h"
 
 
 Serial pc(USBTX, USBRX);
@@ -23,16 +24,54 @@
 bool chipDetected       = false;
 bool operationMode      = true; //the MBED starts in operation mode.
 
-
+void processState(StateMachine stateMachine){
+   switch(stateMachine){    
+      case INITIALISING:
+        setupLCD();
+        printLCD("Welcome to the  Chipin Sorter");
+        wait(1);
+      break;
+      case READING_RGB_VALUES:
+        readChipNumbers();
+      break;
+      case DISPENSE_RED:
+        printLCD("DISPENSING A RED CHIP");
+        select = 0; //Setting to operation mode just in case it has not been set.
+        dispenseBit1 = 0;
+        dispenseBit2 = 0;
+        startDispense = 1;
+        wait(0.001);
+        startDispense = false;
+        //wait(1); //temporary delay
+        printLCD("");
+      break;
+    }
+}
       
 int main() { 
     stateMachine = INITIALISING;
+    processState(stateMachine);
     writeFile(2,6,22);
-    readChipNumbers();
-    setupLCD();
-    printLCD("Welcome to the  Chipin Sorter");
-    wait(1);
-    printStoredChipValues();
+    stateMachine = READING_RGB_VALUES;
+    processState(stateMachine);
+    
+    while(true){
+        stateMachine = DISPENSE_RED;
+        processState(stateMachine);
+        while(!complete){
+            printLCD("Waiting to complete");
+            wait(0.1);
+        }
+        printLCD("Complete");
+        wait(1);
+    }
+    
+    
+    
+    
+    
+    
+    //printStoredChipValues();
 /*     
     while(1){
        if(par_port->read_bit(11)) resetForNextCustomer();
@@ -53,13 +92,13 @@
         }
     */
     
-    setLEDcolour(255,0,0);
+   /* setLEDcolour(255,0,0);
     wait(0.1);
     setLEDcolour(0,255,0);
      wait(0.1);
     setLEDcolour(0,0,255);
     wait(0.1);
     
-    displayOperationMode();    
+    displayOperationMode();  */  
 
     }
\ No newline at end of file