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

Committer:
IonSystems
Date:
Mon Nov 10 16:32:44 2014 +0000
Revision:
8:b7771391adc9
Parent:
7:6ba00694f9cd
Child:
9:8d78eb55ad5e
added red dispense test

Who changed what in which revision?

UserRevisionLine numberNew contents of line
IonSystems 0:8d54ffcf256e 1 #include "mbed.h"
IonSystems 6:e64796f1f384 2 #include <sstream>
IonSystems 6:e64796f1f384 3 #include "lcdCommands.h"
IonSystems 6:e64796f1f384 4 #include "mbedStorage.h"
IonSystems 6:e64796f1f384 5 #include "rgbLED.h"
IonSystems 6:e64796f1f384 6 #include "mbedLCD.h"
IonSystems 7:6ba00694f9cd 7 #include "stateMachine.h"
IonSystems 8:b7771391adc9 8 #include "FPGAcomms.h"
IonSystems 5:644bca33c1ca 9
IonSystems 0:8d54ffcf256e 10
IonSystems 6:e64796f1f384 11 Serial pc(USBTX, USBRX);
IonSystems 3:97668a4cd69d 12
IonSystems 7:6ba00694f9cd 13 StateMachine stateMachine;
IonSystems 7:6ba00694f9cd 14
IonSystems 3:97668a4cd69d 15
IonSystems 6:e64796f1f384 16 //Boolean values to easily enable and disable certain features for individual testing
IonSystems 6:e64796f1f384 17 bool colourSensor = true;
IonSystems 6:e64796f1f384 18 bool cardReader = true;
IonSystems 6:e64796f1f384 19 bool sorter = true;
IonSystems 6:e64796f1f384 20 bool dispensor = true;
IonSystems 6:e64796f1f384 21
IonSystems 6:e64796f1f384 22 bool cardDataAcquired = false;
IonSystems 6:e64796f1f384 23 bool colourDataAcquired = false;
IonSystems 6:e64796f1f384 24 bool chipDetected = false;
IonSystems 6:e64796f1f384 25 bool operationMode = true; //the MBED starts in operation mode.
IonSystems 3:97668a4cd69d 26
IonSystems 8:b7771391adc9 27 void processState(StateMachine stateMachine){
IonSystems 8:b7771391adc9 28 switch(stateMachine){
IonSystems 8:b7771391adc9 29 case INITIALISING:
IonSystems 8:b7771391adc9 30 setupLCD();
IonSystems 8:b7771391adc9 31 printLCD("Welcome to the Chipin Sorter");
IonSystems 8:b7771391adc9 32 wait(1);
IonSystems 8:b7771391adc9 33 break;
IonSystems 8:b7771391adc9 34 case READING_RGB_VALUES:
IonSystems 8:b7771391adc9 35 readChipNumbers();
IonSystems 8:b7771391adc9 36 break;
IonSystems 8:b7771391adc9 37 case DISPENSE_RED:
IonSystems 8:b7771391adc9 38 printLCD("DISPENSING A RED CHIP");
IonSystems 8:b7771391adc9 39 select = 0; //Setting to operation mode just in case it has not been set.
IonSystems 8:b7771391adc9 40 dispenseBit1 = 0;
IonSystems 8:b7771391adc9 41 dispenseBit2 = 0;
IonSystems 8:b7771391adc9 42 startDispense = 1;
IonSystems 8:b7771391adc9 43 wait(0.001);
IonSystems 8:b7771391adc9 44 startDispense = false;
IonSystems 8:b7771391adc9 45 //wait(1); //temporary delay
IonSystems 8:b7771391adc9 46 printLCD("");
IonSystems 8:b7771391adc9 47 break;
IonSystems 8:b7771391adc9 48 }
IonSystems 8:b7771391adc9 49 }
IonSystems 6:e64796f1f384 50
IonSystems 6:e64796f1f384 51 int main() {
IonSystems 7:6ba00694f9cd 52 stateMachine = INITIALISING;
IonSystems 8:b7771391adc9 53 processState(stateMachine);
IonSystems 7:6ba00694f9cd 54 writeFile(2,6,22);
IonSystems 8:b7771391adc9 55 stateMachine = READING_RGB_VALUES;
IonSystems 8:b7771391adc9 56 processState(stateMachine);
IonSystems 8:b7771391adc9 57
IonSystems 8:b7771391adc9 58 while(true){
IonSystems 8:b7771391adc9 59 stateMachine = DISPENSE_RED;
IonSystems 8:b7771391adc9 60 processState(stateMachine);
IonSystems 8:b7771391adc9 61 while(!complete){
IonSystems 8:b7771391adc9 62 printLCD("Waiting to complete");
IonSystems 8:b7771391adc9 63 wait(0.1);
IonSystems 8:b7771391adc9 64 }
IonSystems 8:b7771391adc9 65 printLCD("Complete");
IonSystems 8:b7771391adc9 66 wait(1);
IonSystems 8:b7771391adc9 67 }
IonSystems 8:b7771391adc9 68
IonSystems 8:b7771391adc9 69
IonSystems 8:b7771391adc9 70
IonSystems 8:b7771391adc9 71
IonSystems 8:b7771391adc9 72
IonSystems 8:b7771391adc9 73
IonSystems 8:b7771391adc9 74 //printStoredChipValues();
IonSystems 6:e64796f1f384 75 /*
IonSystems 0:8d54ffcf256e 76 while(1){
IonSystems 3:97668a4cd69d 77 if(par_port->read_bit(11)) resetForNextCustomer();
IonSystems 7:6ba00694f9cd 78
IonSystems 3:97668a4cd69d 79 if(cardDetect & !cardDataAcquired) cardAcquisition();
IonSystems 3:97668a4cd69d 80 setLEDs();
IonSystems 3:97668a4cd69d 81 readButtons();
IonSystems 3:97668a4cd69d 82
IonSystems 4:f3be545b3826 83 if(chipDetected & !colourDataAcquired){
IonSystems 4:f3be545b3826 84 Colour colour = readColourSensor();
IonSystems 4:f3be545b3826 85 sendColourSignal(colour);
IonSystems 4:f3be545b3826 86 }
IonSystems 4:f3be545b3826 87
IonSystems 5:644bca33c1ca 88 writeFile(redQueue, greenQueue, blueQueue);
IonSystems 4:f3be545b3826 89 readFile();
IonSystems 4:f3be545b3826 90 wait(2);
IonSystems 4:f3be545b3826 91
IonSystems 0:8d54ffcf256e 92 }
IonSystems 6:e64796f1f384 93 */
IonSystems 6:e64796f1f384 94
IonSystems 8:b7771391adc9 95 /* setLEDcolour(255,0,0);
IonSystems 6:e64796f1f384 96 wait(0.1);
IonSystems 6:e64796f1f384 97 setLEDcolour(0,255,0);
IonSystems 6:e64796f1f384 98 wait(0.1);
IonSystems 6:e64796f1f384 99 setLEDcolour(0,0,255);
IonSystems 6:e64796f1f384 100 wait(0.1);
IonSystems 6:e64796f1f384 101
IonSystems 8:b7771391adc9 102 displayOperationMode(); */
IonSystems 3:97668a4cd69d 103
IonSystems 6:e64796f1f384 104 }