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:
6:e64796f1f384
Child:
7:6ba00694f9cd
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/serialCommunication.h	Fri Nov 07 20:16:23 2014 +0000
@@ -0,0 +1,108 @@
+char readBit(int bitNumber){
+        int value = 0;
+        switch(bitNumber){
+            case 1:
+                value = cardBit1;
+            break;
+            case 2:
+                value = cardBit2;
+            break;
+            case 3:
+                 value = cardBit3;
+            break;
+            case 4:
+                value = cardBit4;
+            break;
+            case 5:
+                value = cardBit5;
+            break;
+            case 6:
+                value = cardBit6;
+            break;
+            }
+            return valueToChar(value);
+    }
+    
+    void processMessage(char c){
+     switch(c){
+            case 'a' : //servo 1 clockwise
+                sendCharacter('a'); //bounce back for acknowledgement
+                printLCD("S1 clockwise");
+            break;
+            case 'b' :  //servo 1 anticlockwise
+                sendCharacter('b');  //bounce back for acknowledgement
+                printLCD("S1 anticlockwise");
+            break;
+            case 'c':
+                sendCharacter('c'); //bounce back for acknowledgement
+                printLCD("S1 stop");
+            break;
+            case 'C':// Read card command
+                sendCharacter('R'); //Notify PC that command has been recieved
+                printLCD("Reading Card");
+                //read card here
+                char value = ' ';
+                for(int num = 1;num <= 6;num++){
+                    value = readBit(num);
+                   // sendCharacter('R');
+                    sendCharacter(value);
+                    printLCD("Bit read");
+                    //wait(0.1);
+                }
+                sendCharacter('C'); //Tells PC that the card has been read
+                printLCD("Card read done");
+            break;
+            case 'X':
+                sendCharacter('X'); //Notify the PC that this is an MBED
+                printLCD("Connected to PC");
+            break;
+            case 'd':   //Dispense a chip
+                sendCharacter('D');
+                printLCD("Dispensing chip");
+              
+                //read from color sensor
+                //convert readings to colour
+                //convert colour to 3-bit colour code
+                //set the FPGA colour inputs to the colour code
+                startSort = true; 
+            break;
+            case 't'://Test 180 servo
+            sendCharacter('T');
+            printLCD("Servo signal on");
+            servoTest = true;
+            break;
+            case 'w'://Test 180 servo
+            sendCharacter('W');
+            printLCD("Servo signal off");
+            servoTest = false;
+            break;
+        
+        
+        else if (operationMode){
+            switch(c){
+                case 'n':// Start sorting
+                    sendCharacter('N'); //Confirm to PC that we are processing the instruction.
+                    startSort = true; //Pulse the startSort control line to FPGA
+                    wait(0.1);
+                    startSort = false;
+                break;
+                case 'o':   //Start dispensing
+                    sendCharacter('O');
+                    startDispense = true; //Pulse the startDispense control line to FPGA
+                    wait(0.1);
+                    startDispense = false;
+                break;
+                case 'p':   //
+                    sendCharacter('P');
+                break;
+                }
+           }
+}
+
+void sendCharacter(char ch){
+        pc.putc(ch);
+}
+
+void sendString(char* ch){
+        pc.puts(ch);
+}
\ No newline at end of file