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:
Thu Nov 06 18:31:50 2014 +0000
Revision:
5:644bca33c1ca
Parent:
4:f3be545b3826
Child:
6:e64796f1f384
This is what is left after Euan took over. The binary file has been halfed i.e most of the code I made has been removed.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
IonSystems 0:8d54ffcf256e 1 #include "mbed.h"
IonSystems 0:8d54ffcf256e 2 #include "MCP23017.h"
IonSystems 0:8d54ffcf256e 3 #include "WattBob_TextLCD.h"
IonSystems 5:644bca33c1ca 4
IonSystems 5:644bca33c1ca 5 /*
IonSystems 0:8d54ffcf256e 6 #include "TCS3472_I2C.h"
IonSystems 3:97668a4cd69d 7 #include <string>
IonSystems 4:f3be545b3826 8 #include "Colour.h"
IonSystems 0:8d54ffcf256e 9
IonSystems 3:97668a4cd69d 10 //Setup test LEDs
IonSystems 3:97668a4cd69d 11 DigitalOut testLED1(LED1);
IonSystems 3:97668a4cd69d 12 DigitalOut testLED2(LED2);
IonSystems 3:97668a4cd69d 13 DigitalOut testLED3(LED3);
IonSystems 3:97668a4cd69d 14 DigitalOut testLED4(LED4);
IonSystems 3:97668a4cd69d 15
IonSystems 3:97668a4cd69d 16 //Setup Buttons
IonSystems 3:97668a4cd69d 17 DigitalIn testButton1(P1_8);
IonSystems 0:8d54ffcf256e 18
IonSystems 0:8d54ffcf256e 19 //Boolean values to easily enable and disable certain features for individual testing
IonSystems 5:644bca33c1ca 20 bool colourSensor = true;
IonSystems 0:8d54ffcf256e 21 bool cardReader = true;
IonSystems 0:8d54ffcf256e 22 bool sorter = true;
IonSystems 0:8d54ffcf256e 23 bool dispensor = true;
IonSystems 3:97668a4cd69d 24 */
IonSystems 0:8d54ffcf256e 25 /*
IonSystems 0:8d54ffcf256e 26 There are two high level states representing the two main
IonSystems 0:8d54ffcf256e 27 functionalities of the MBED: Maintenance mode and Operation mode.
IonSystems 0:8d54ffcf256e 28
IonSystems 0:8d54ffcf256e 29 When operationMode is true, the MBED is in operation mode.
IonSystems 0:8d54ffcf256e 30 When operationMode is false, the MBED is in maintenance mode.
IonSystems 0:8d54ffcf256e 31 */
IonSystems 0:8d54ffcf256e 32
IonSystems 5:644bca33c1ca 33 //bool operationMode = true; //the MBED starts in operation mode.
IonSystems 0:8d54ffcf256e 34
IonSystems 0:8d54ffcf256e 35 #define BACK_LIGHT_ON(INTERFACE) INTERFACE->write_bit(1,BL_BIT)
IonSystems 0:8d54ffcf256e 36 #define BACK_LIGHT_OFF(INTERFACE) INTERFACE->write_bit(0,BL_BIT)
IonSystems 0:8d54ffcf256e 37
IonSystems 0:8d54ffcf256e 38 //Creating all the global variables.
IonSystems 0:8d54ffcf256e 39 MCP23017 *par_port;
IonSystems 0:8d54ffcf256e 40 WattBob_TextLCD *lcd;
IonSystems 4:f3be545b3826 41 Serial pc(USBTX, USBRX);
IonSystems 4:f3be545b3826 42 //Stuff that saves stuff to the MBED.
IonSystems 5:644bca33c1ca 43 //LocalFileSystem local("local");
IonSystems 4:f3be545b3826 44
IonSystems 4:f3be545b3826 45
IonSystems 5:644bca33c1ca 46 /*
IonSystems 5:644bca33c1ca 47 void writeFile(int r, int g, int b){
IonSystems 4:f3be545b3826 48 FILE* File1 = fopen("/local/datafile.txt","w"); // open file
IonSystems 5:644bca33c1ca 49 fputc(r, File1); // put char (data value) into file
IonSystems 5:644bca33c1ca 50 fputc(g, File1); // put char (data value) into file
IonSystems 5:644bca33c1ca 51 fputc(b, File1); // put char (data value) into file
IonSystems 4:f3be545b3826 52 fclose(File1); // close file
IonSystems 4:f3be545b3826 53 }
IonSystems 4:f3be545b3826 54
IonSystems 4:f3be545b3826 55 int readFile(){
IonSystems 4:f3be545b3826 56 FILE* File2 = fopen ("/local/datafile.txt","r"); // open file for reading
IonSystems 4:f3be545b3826 57 int read_var = fgetc(File2); // read first data value
IonSystems 4:f3be545b3826 58 fclose(File2); // close file
IonSystems 4:f3be545b3826 59 return read_var;
IonSystems 4:f3be545b3826 60 }
IonSystems 5:644bca33c1ca 61 int redQueue = readFile();
IonSystems 5:644bca33c1ca 62 int greenQueue = readFile();
IonSystems 5:644bca33c1ca 63 int blueQueue = readFile();
IonSystems 0:8d54ffcf256e 64
IonSystems 0:8d54ffcf256e 65 //Setup colour sensor variables
IonSystems 0:8d54ffcf256e 66 int rgb_readings[4];
IonSystems 0:8d54ffcf256e 67 double rMax = 9244;
IonSystems 0:8d54ffcf256e 68 double gMax = 3194;
IonSystems 0:8d54ffcf256e 69 double bMax = 3590;
IonSystems 3:97668a4cd69d 70 TCS3472_I2C rgb_sensor(p28,p27); //p28 =sda, p27=scl
IonSystems 3:97668a4cd69d 71 //thresholds are in the RGB format.
IonSystems 4:f3be545b3826 72 int redLT [3] = {79,23,41};
IonSystems 4:f3be545b3826 73 int redUT [3]= {92,28,49};
IonSystems 4:f3be545b3826 74 int greenLT [3] = {46,81,61};
IonSystems 4:f3be545b3826 75 int greenUT [3]= {60,107,81};
IonSystems 4:f3be545b3826 76 int blueLT [3]= {25,47,47};
IonSystems 4:f3be545b3826 77 int blueUT [3]= {28,52,52};
IonSystems 4:f3be545b3826 78
IonSystems 5:644bca33c1ca 79
IonSystems 0:8d54ffcf256e 80
IonSystems 3:97668a4cd69d 81 //setup Card Reader pins
IonSystems 0:8d54ffcf256e 82 DigitalIn cardBit1(p21);
IonSystems 0:8d54ffcf256e 83 DigitalIn cardBit2(p22);
IonSystems 0:8d54ffcf256e 84 DigitalIn cardBit3(p23);
IonSystems 0:8d54ffcf256e 85 DigitalIn cardBit4(p24);
IonSystems 0:8d54ffcf256e 86 DigitalIn cardBit5(p25);
IonSystems 0:8d54ffcf256e 87 DigitalIn cardBit6(p26);
IonSystems 3:97668a4cd69d 88 DigitalIn cardDetect(p29);
IonSystems 3:97668a4cd69d 89 bool cardDataAcquired = false;
IonSystems 3:97668a4cd69d 90 bool colourDataAcquired = false;
IonSystems 3:97668a4cd69d 91 bool chipDetected = false;
IonSystems 0:8d54ffcf256e 92
IonSystems 0:8d54ffcf256e 93 //Setup pins to FPGA
IonSystems 0:8d54ffcf256e 94 DigitalOut startSort(p5); //A positive edge tells the FPGA to start sorting.
IonSystems 5:644bca33c1ca 95 The command codes for the three sort select bits(ColourBit1 - ColourBit2)
IonSystems 0:8d54ffcf256e 96 000 Sort red chip
IonSystems 0:8d54ffcf256e 97 001 Sort green chip
IonSystems 0:8d54ffcf256e 98 010 Sort blue chip
IonSystems 0:8d54ffcf256e 99 011 Bin the chip
IonSystems 0:8d54ffcf256e 100 100 Recycle the chip
IonSystems 0:8d54ffcf256e 101 101 Nothing
IonSystems 0:8d54ffcf256e 102 110 Nothing
IonSystems 0:8d54ffcf256e 103 111 Nothing
IonSystems 0:8d54ffcf256e 104 */
IonSystems 5:644bca33c1ca 105 /*
IonSystems 4:f3be545b3826 106 DigitalOut colourBit1(p6); //The 3 bits below are select bits for the sorter.
IonSystems 4:f3be545b3826 107 DigitalOut colourBit2(p7);
IonSystems 4:f3be545b3826 108 DigitalOut colourBit3(p8);
IonSystems 0:8d54ffcf256e 109 DigitalOut startDispense(p9); //A positive edge tells the FPGA to start dispensing.
IonSystems 5:644bca33c1ca 110
IonSystems 0:8d54ffcf256e 111 00 Dispense red chip
IonSystems 0:8d54ffcf256e 112 01 Dispense green chip
IonSystems 0:8d54ffcf256e 113 10 Dispense blue chip
IonSystems 0:8d54ffcf256e 114 11 Nothing
IonSystems 0:8d54ffcf256e 115 */
IonSystems 5:644bca33c1ca 116 /*
IonSystems 0:8d54ffcf256e 117 DigitalOut DispenseBit1(p10); //The 2 bits below are select bits for the dispenser.
IonSystems 0:8d54ffcf256e 118 DigitalOut DispenseBit2(p11);
IonSystems 0:8d54ffcf256e 119
IonSystems 3:97668a4cd69d 120 DigitalOut servoTest(p21); //for basic servo test fro deadline day 31/10/14
IonSystems 3:97668a4cd69d 121
IonSystems 3:97668a4cd69d 122 //Global card bits
IonSystems 3:97668a4cd69d 123 int cardValue1 = 0;
IonSystems 3:97668a4cd69d 124 int cardValue2 = 0;
IonSystems 3:97668a4cd69d 125 int cardValue3 = 0;
IonSystems 3:97668a4cd69d 126 int cardValue4 = 0;
IonSystems 3:97668a4cd69d 127 int cardValue5 = 0;
IonSystems 3:97668a4cd69d 128 int cardValue6 = 0;
IonSystems 0:8d54ffcf256e 129
IonSystems 0:8d54ffcf256e 130 //Functions go here
IonSystems 0:8d54ffcf256e 131 void sendCharacter(char ch){
IonSystems 0:8d54ffcf256e 132 pc.putc(ch);
IonSystems 0:8d54ffcf256e 133 }
IonSystems 0:8d54ffcf256e 134
IonSystems 3:97668a4cd69d 135
IonSystems 3:97668a4cd69d 136 void setLEDs(){
IonSystems 3:97668a4cd69d 137 testLED1 = cardDetect;
IonSystems 3:97668a4cd69d 138 testLED4 = true;
IonSystems 3:97668a4cd69d 139 }
IonSystems 3:97668a4cd69d 140
IonSystems 5:644bca33c1ca 141 A simple print function for use on the MBED LCD Screen.
IonSystems 3:97668a4cd69d 142 * Will format a char array into two lines and display the char array on the LCD.
IonSystems 5:644bca33c1ca 143 */
IonSystems 5:644bca33c1ca 144 /*
IonSystems 3:97668a4cd69d 145 void printLCD(const char * text){
IonSystems 3:97668a4cd69d 146 std::string txt_str = std::string(text); //Convert ther character array to a std::string,
IonSystems 3:97668a4cd69d 147 //to use in the string manipulation functions.
IonSystems 0:8d54ffcf256e 148 lcd->reset();
IonSystems 3:97668a4cd69d 149 if(txt_str.length() > 32){
IonSystems 3:97668a4cd69d 150 int length = txt_str.length();
IonSystems 3:97668a4cd69d 151 txt_str = txt_str.erase(32,length-32);
IonSystems 3:97668a4cd69d 152 lcd->locate(0,0); //Going to new line
IonSystems 3:97668a4cd69d 153 text = txt_str.c_str();
IonSystems 3:97668a4cd69d 154 }
IonSystems 3:97668a4cd69d 155 if(txt_str.length() > 16){
IonSystems 3:97668a4cd69d 156 string line1 = txt_str.substr(0,16);
IonSystems 3:97668a4cd69d 157 string line2 = txt_str.substr(16,16);
IonSystems 3:97668a4cd69d 158 lcd->locate(0,0); //Going to new line
IonSystems 3:97668a4cd69d 159 lcd->printf(line1.c_str());
IonSystems 3:97668a4cd69d 160 lcd->locate(1,0); //Going to new line
IonSystems 3:97668a4cd69d 161 lcd->printf(line2.c_str());
IonSystems 3:97668a4cd69d 162 lcd->locate(0,0); //Going to new line
IonSystems 3:97668a4cd69d 163 }
IonSystems 3:97668a4cd69d 164
IonSystems 0:8d54ffcf256e 165 }
IonSystems 3:97668a4cd69d 166
IonSystems 3:97668a4cd69d 167
IonSystems 3:97668a4cd69d 168 void readButtons(){
IonSystems 3:97668a4cd69d 169 chipDetected = par_port->read_bit(8);
IonSystems 3:97668a4cd69d 170 testLED1 = par_port->read_bit(8);
IonSystems 3:97668a4cd69d 171
IonSystems 3:97668a4cd69d 172 }
IonSystems 5:644bca33c1ca 173 Reads all 6 bits from the card IO pins and prints them to the MBED LCD.
IonSystems 3:97668a4cd69d 174 * Stores the values read to the global variables cardValue1 to cardValue6.
IonSystems 3:97668a4cd69d 175 */
IonSystems 5:644bca33c1ca 176 /*
IonSystems 3:97668a4cd69d 177 void cardAcquisition(){
IonSystems 3:97668a4cd69d 178 lcd->reset();
IonSystems 3:97668a4cd69d 179 lcd->locate(0,0); //Going to new line
IonSystems 3:97668a4cd69d 180 if(cardBit1) lcd->printf("p1=1,");
IonSystems 3:97668a4cd69d 181 else lcd->printf("p1=0,");
IonSystems 3:97668a4cd69d 182 cardValue1 = cardBit1;
IonSystems 3:97668a4cd69d 183
IonSystems 3:97668a4cd69d 184 if(cardBit2) lcd->printf("p2=1,");
IonSystems 3:97668a4cd69d 185 else lcd->printf("p2=0,");
IonSystems 3:97668a4cd69d 186 cardValue2 = cardBit2;
IonSystems 3:97668a4cd69d 187
IonSystems 3:97668a4cd69d 188 if(cardBit3) lcd->printf("p3=1");
IonSystems 3:97668a4cd69d 189 else lcd->printf("p3=0");
IonSystems 3:97668a4cd69d 190 cardValue3 = cardBit3;
IonSystems 3:97668a4cd69d 191
IonSystems 3:97668a4cd69d 192 lcd->locate(1,0); //Going to new line
IonSystems 3:97668a4cd69d 193
IonSystems 3:97668a4cd69d 194 if(cardBit4) lcd->printf("p4=1");
IonSystems 3:97668a4cd69d 195 else lcd->printf("p4=0,");
IonSystems 3:97668a4cd69d 196 cardValue4 = cardBit4;
IonSystems 3:97668a4cd69d 197
IonSystems 3:97668a4cd69d 198
IonSystems 3:97668a4cd69d 199 if(cardBit5) lcd->printf("p5=1,");
IonSystems 3:97668a4cd69d 200 else lcd->printf("p5=0,");
IonSystems 3:97668a4cd69d 201 cardValue5 = cardBit5;
IonSystems 3:97668a4cd69d 202
IonSystems 3:97668a4cd69d 203 if(cardBit6) lcd->printf("p6=1");
IonSystems 3:97668a4cd69d 204 else lcd->printf("p6=0");
IonSystems 3:97668a4cd69d 205 cardValue6 = cardBit6;
IonSystems 3:97668a4cd69d 206
IonSystems 3:97668a4cd69d 207 cardDataAcquired = true;
IonSystems 3:97668a4cd69d 208
IonSystems 3:97668a4cd69d 209 }
IonSystems 5:644bca33c1ca 210 valueToChar(int value):
IonSystems 1:a8a01df48d1a 211 Expects an int value what it 0 or 1.
IonSystems 1:a8a01df48d1a 212 Returns the int value as a char.
IonSystems 1:a8a01df48d1a 213 0 will return '0'
IonSystems 1:a8a01df48d1a 214 1 will return '1'
IonSystems 1:a8a01df48d1a 215 Used to read the bits in the card reader.
IonSystems 1:a8a01df48d1a 216 */
IonSystems 5:644bca33c1ca 217 /*
IonSystems 0:8d54ffcf256e 218 char valueToChar(int value){
IonSystems 1:a8a01df48d1a 219 if(value == 0){
IonSystems 0:8d54ffcf256e 220 return '0';
IonSystems 1:a8a01df48d1a 221 }else if(value == 1){
IonSystems 1:a8a01df48d1a 222 return '1';
IonSystems 1:a8a01df48d1a 223 }else{
IonSystems 1:a8a01df48d1a 224 return NULL;
IonSystems 1:a8a01df48d1a 225 }
IonSystems 0:8d54ffcf256e 226 }
IonSystems 5:644bca33c1ca 227 readBit(int bitNumber):
IonSystems 0:8d54ffcf256e 228 Takes a bit number between 1 and 6 inclusive.
IonSystems 0:8d54ffcf256e 229 Returns the value of the cardBit associated with the bit number as a char.
IonSystems 0:8d54ffcf256e 230 */
IonSystems 5:644bca33c1ca 231 /*
IonSystems 0:8d54ffcf256e 232 char readBit(int bitNumber){
IonSystems 0:8d54ffcf256e 233 int value = 0;
IonSystems 0:8d54ffcf256e 234 switch(bitNumber){
IonSystems 0:8d54ffcf256e 235 case 1:
IonSystems 0:8d54ffcf256e 236 value = cardBit1;
IonSystems 0:8d54ffcf256e 237 break;
IonSystems 0:8d54ffcf256e 238 case 2:
IonSystems 0:8d54ffcf256e 239 value = cardBit2;
IonSystems 0:8d54ffcf256e 240 break;
IonSystems 0:8d54ffcf256e 241 case 3:
IonSystems 0:8d54ffcf256e 242 value = cardBit3;
IonSystems 0:8d54ffcf256e 243 break;
IonSystems 0:8d54ffcf256e 244 case 4:
IonSystems 0:8d54ffcf256e 245 value = cardBit4;
IonSystems 0:8d54ffcf256e 246 break;
IonSystems 0:8d54ffcf256e 247 case 5:
IonSystems 0:8d54ffcf256e 248 value = cardBit5;
IonSystems 0:8d54ffcf256e 249 break;
IonSystems 0:8d54ffcf256e 250 case 6:
IonSystems 0:8d54ffcf256e 251 value = cardBit6;
IonSystems 0:8d54ffcf256e 252 break;
IonSystems 0:8d54ffcf256e 253 }
IonSystems 0:8d54ffcf256e 254 return valueToChar(value);
IonSystems 0:8d54ffcf256e 255 }
IonSystems 5:644bca33c1ca 256 processMessage(char c):
IonSystems 1:a8a01df48d1a 257 Runs when the MBED recieves a character from the PC.
IonSystems 1:a8a01df48d1a 258 Carries out tasks based on the char value.
IonSystems 1:a8a01df48d1a 259 An acknowledge signal is always send back to the PC so that it knows the MBED
IonSystems 1:a8a01df48d1a 260 has recieved the command.
IonSystems 1:a8a01df48d1a 261 Has two case statements: one for maintenance mode and one for operation mode.
IonSystems 0:8d54ffcf256e 262 */
IonSystems 5:644bca33c1ca 263 /*
IonSystems 0:8d54ffcf256e 264 void processMessage(char c){
IonSystems 3:97668a4cd69d 265 switch(c){
IonSystems 0:8d54ffcf256e 266 case 'a' : //servo 1 clockwise
IonSystems 0:8d54ffcf256e 267 sendCharacter('a'); //bounce back for acknowledgement
IonSystems 0:8d54ffcf256e 268 printLCD("S1 clockwise");
IonSystems 0:8d54ffcf256e 269 break;
IonSystems 0:8d54ffcf256e 270 case 'b' : //servo 1 anticlockwise
IonSystems 0:8d54ffcf256e 271 sendCharacter('b'); //bounce back for acknowledgement
IonSystems 0:8d54ffcf256e 272 printLCD("S1 anticlockwise");
IonSystems 0:8d54ffcf256e 273 break;
IonSystems 0:8d54ffcf256e 274 case 'c':
IonSystems 0:8d54ffcf256e 275 sendCharacter('c'); //bounce back for acknowledgement
IonSystems 0:8d54ffcf256e 276 printLCD("S1 stop");
IonSystems 0:8d54ffcf256e 277 break;
IonSystems 0:8d54ffcf256e 278 case 'C':// Read card command
IonSystems 0:8d54ffcf256e 279 sendCharacter('R'); //Notify PC that command has been recieved
IonSystems 0:8d54ffcf256e 280 printLCD("Reading Card");
IonSystems 0:8d54ffcf256e 281 //read card here
IonSystems 0:8d54ffcf256e 282 char value = ' ';
IonSystems 0:8d54ffcf256e 283 for(int num = 1;num <= 6;num++){
IonSystems 0:8d54ffcf256e 284 value = readBit(num);
IonSystems 0:8d54ffcf256e 285 // sendCharacter('R');
IonSystems 0:8d54ffcf256e 286 sendCharacter(value);
IonSystems 0:8d54ffcf256e 287 printLCD("Bit read");
IonSystems 0:8d54ffcf256e 288 //wait(0.1);
IonSystems 0:8d54ffcf256e 289 }
IonSystems 0:8d54ffcf256e 290 sendCharacter('C'); //Tells PC that the card has been read
IonSystems 3:97668a4cd69d 291 printLCD("Card read done");
IonSystems 0:8d54ffcf256e 292 break;
IonSystems 0:8d54ffcf256e 293 case 'X':
IonSystems 0:8d54ffcf256e 294 sendCharacter('X'); //Notify the PC that this is an MBED
IonSystems 0:8d54ffcf256e 295 printLCD("Connected to PC");
IonSystems 0:8d54ffcf256e 296 break;
IonSystems 2:168850019d5a 297 case 'd': //Dispense a chip
IonSystems 3:97668a4cd69d 298 sendCharacter('D');
IonSystems 2:168850019d5a 299 printLCD("Dispensing chip");
IonSystems 2:168850019d5a 300
IonSystems 2:168850019d5a 301 //read from color sensor
IonSystems 2:168850019d5a 302 //convert readings to colour
IonSystems 2:168850019d5a 303 //convert colour to 3-bit colour code
IonSystems 2:168850019d5a 304 //set the FPGA colour inputs to the colour code
IonSystems 3:97668a4cd69d 305 startSort = true;
IonSystems 3:97668a4cd69d 306 break;
IonSystems 3:97668a4cd69d 307 case 't'://Test 180 servo
IonSystems 3:97668a4cd69d 308 sendCharacter('T');
IonSystems 3:97668a4cd69d 309 printLCD("Servo signal on");
IonSystems 3:97668a4cd69d 310 servoTest = true;
IonSystems 2:168850019d5a 311 break;
IonSystems 3:97668a4cd69d 312 case 'w'://Test 180 servo
IonSystems 3:97668a4cd69d 313 sendCharacter('W');
IonSystems 3:97668a4cd69d 314 printLCD("Servo signal off");
IonSystems 3:97668a4cd69d 315 servoTest = false;
IonSystems 3:97668a4cd69d 316 break;
IonSystems 3:97668a4cd69d 317
IonSystems 3:97668a4cd69d 318
IonSystems 5:644bca33c1ca 319 else if (operationMode){
IonSystems 0:8d54ffcf256e 320 switch(c){
IonSystems 1:a8a01df48d1a 321 case 'n':// Start sorting
IonSystems 1:a8a01df48d1a 322 sendCharacter('N'); //Confirm to PC that we are processing the instruction.
IonSystems 1:a8a01df48d1a 323 startSort = true; //Pulse the startSort control line to FPGA
IonSystems 1:a8a01df48d1a 324 wait(0.1);
IonSystems 1:a8a01df48d1a 325 startSort = false;
IonSystems 1:a8a01df48d1a 326 break;
IonSystems 1:a8a01df48d1a 327 case 'o': //Start dispensing
IonSystems 1:a8a01df48d1a 328 sendCharacter('O');
IonSystems 1:a8a01df48d1a 329 startDispense = true; //Pulse the startDispense control line to FPGA
IonSystems 1:a8a01df48d1a 330 wait(0.1);
IonSystems 1:a8a01df48d1a 331 startDispense = false;
IonSystems 0:8d54ffcf256e 332 break;
IonSystems 2:168850019d5a 333 case 'p': //
IonSystems 2:168850019d5a 334 sendCharacter('P');
IonSystems 2:168850019d5a 335 break;
IonSystems 0:8d54ffcf256e 336 }
IonSystems 5:644bca33c1ca 337 }
IonSystems 0:8d54ffcf256e 338 }
IonSystems 5:644bca33c1ca 339
IonSystems 3:97668a4cd69d 340
IonSystems 5:644bca33c1ca 341
IonSystems 5:644bca33c1ca 342
IonSystems 4:f3be545b3826 343
IonSystems 3:97668a4cd69d 344 void resetForNextCustomer(){
IonSystems 3:97668a4cd69d 345 colourDataAcquired = false;
IonSystems 3:97668a4cd69d 346 cardDataAcquired = false;
IonSystems 3:97668a4cd69d 347 printLCD("Ready for next customer");
IonSystems 3:97668a4cd69d 348 }
IonSystems 5:644bca33c1ca 349 */
IonSystems 0:8d54ffcf256e 350 int main() {
IonSystems 0:8d54ffcf256e 351 //Setting up all the global variables
IonSystems 0:8d54ffcf256e 352 par_port = new MCP23017(p9, p10, 0x40);
IonSystems 0:8d54ffcf256e 353 par_port->config(0x0F00, 0x0F00, 0x0F00); // configure MCP23017 chip on WattBob
IonSystems 0:8d54ffcf256e 354 BACK_LIGHT_ON(par_port);
IonSystems 0:8d54ffcf256e 355 lcd = new WattBob_TextLCD(par_port);
IonSystems 5:644bca33c1ca 356 //rgb_sensor.enablePowerAndRGBC();
IonSystems 5:644bca33c1ca 357 //rgb_sensor.setIntegrationTime(100);
IonSystems 0:8d54ffcf256e 358 //Writing initial text on LCD
IonSystems 5:644bca33c1ca 359 lcd->printf("Welcome to the");
IonSystems 5:644bca33c1ca 360 lcd->locate(1,0); //Going to new line
IonSystems 5:644bca33c1ca 361 lcd->printf("Chipin Sorter");
IonSystems 3:97668a4cd69d 362
IonSystems 3:97668a4cd69d 363
IonSystems 3:97668a4cd69d 364
IonSystems 5:644bca33c1ca 365 //printLCD("Welcome to the Chipin Sorter");
IonSystems 3:97668a4cd69d 366 wait(1);
IonSystems 3:97668a4cd69d 367 lcd->reset(); //Clear LCD
IonSystems 5:644bca33c1ca 368 /*
IonSystems 0:8d54ffcf256e 369 while(1){
IonSystems 3:97668a4cd69d 370 if(par_port->read_bit(11)) resetForNextCustomer();
IonSystems 3:97668a4cd69d 371 // char c = pc.getc(); //wait for a serial character to be recieved.
IonSystems 3:97668a4cd69d 372 // processMessage(c); //Do something, based on the character recieved.
IonSystems 3:97668a4cd69d 373 if(cardDetect & !cardDataAcquired) cardAcquisition();
IonSystems 3:97668a4cd69d 374 setLEDs();
IonSystems 3:97668a4cd69d 375 readButtons();
IonSystems 3:97668a4cd69d 376
IonSystems 4:f3be545b3826 377 if(chipDetected & !colourDataAcquired){
IonSystems 4:f3be545b3826 378 Colour colour = readColourSensor();
IonSystems 4:f3be545b3826 379 sendColourSignal(colour);
IonSystems 4:f3be545b3826 380 }
IonSystems 4:f3be545b3826 381
IonSystems 5:644bca33c1ca 382 writeFile(redQueue, greenQueue, blueQueue);
IonSystems 4:f3be545b3826 383 readFile();
IonSystems 4:f3be545b3826 384 wait(2);
IonSystems 4:f3be545b3826 385
IonSystems 0:8d54ffcf256e 386 }
IonSystems 0:8d54ffcf256e 387
IonSystems 5:644bca33c1ca 388 */
IonSystems 3:97668a4cd69d 389
IonSystems 0:8d54ffcf256e 390 }