![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
3rd year group project. Electronic and Electrical Engineering. Heriot-Watt University. This is the code for the mbed for the Automatic Little Object Organiser (ALOO).
Dependencies: MCP23017 TCS3472_I2C WattBob_TextLCD mbed
main.cpp@2:7a55cb10259f, 2015-10-30 (annotated)
- Committer:
- dreamselec
- Date:
- Fri Oct 30 07:51:47 2015 +0000
- Revision:
- 2:7a55cb10259f
- Parent:
- 1:92a2a5ef65a8
- Child:
- 3:843b830ee8bd
Added globals class which keeps track of global variables.; Added commander class which is to work together will command controller class from Swift. ; Test show some what parsing capabilities, needs a lot of work to be be fail proof.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dreamselec | 0:fe5cb0a8fc5a | 1 | #include "mbed.h" |
dreamselec | 0:fe5cb0a8fc5a | 2 | #include "WattBob_TextLCD.h" |
dreamselec | 0:fe5cb0a8fc5a | 3 | #include "TCS3472_I2C.h" |
dreamselec | 0:fe5cb0a8fc5a | 4 | #include "MCP23017.h" |
dreamselec | 0:fe5cb0a8fc5a | 5 | #include <string> |
dreamselec | 1:92a2a5ef65a8 | 6 | #include <time.h> |
dreamselec | 2:7a55cb10259f | 7 | //#include <future> |
dreamselec | 2:7a55cb10259f | 8 | #include "globals.h" |
dreamselec | 2:7a55cb10259f | 9 | #include "commander.h" |
dreamselec | 0:fe5cb0a8fc5a | 10 | |
dreamselec | 0:fe5cb0a8fc5a | 11 | #define BACKLIGHT_ON(INTERFACE) INTERFACE->write_bit(1, 4); |
dreamselec | 0:fe5cb0a8fc5a | 12 | #define BACKLIGHT_OFF(INTERFACE) INTERFACE->write_bit(0, 4); |
dreamselec | 0:fe5cb0a8fc5a | 13 | |
dreamselec | 0:fe5cb0a8fc5a | 14 | #define PRINT_LCD(TEXT) lcd->printf(TEXT); |
dreamselec | 0:fe5cb0a8fc5a | 15 | #define CLEAR_LCD() lcd->cls(); |
dreamselec | 0:fe5cb0a8fc5a | 16 | #define LCDFL() lcd->locate(0,0); |
dreamselec | 0:fe5cb0a8fc5a | 17 | #define LCDSL() lcd->locate(1,0); |
dreamselec | 2:7a55cb10259f | 18 | #define D_LEDS_OFF() i2cport->write_bit(0, 12); i2cport->write_bit(0, 13); i2cport->write_bit(0, 14); i2cport->write_bit(0, 15); |
dreamselec | 2:7a55cb10259f | 19 | #define U_LEDS_OFF() myLED1 = 0; myLED2 = 0; myLED3 = 0; myLED4 = 0; |
dreamselec | 0:fe5cb0a8fc5a | 20 | |
dreamselec | 2:7a55cb10259f | 21 | DigitalOut myLED1(LED1); |
dreamselec | 2:7a55cb10259f | 22 | DigitalOut myLED2(LED2); |
dreamselec | 2:7a55cb10259f | 23 | DigitalOut myLED3(LED3); |
dreamselec | 2:7a55cb10259f | 24 | DigitalOut myLED4(LED4); |
dreamselec | 0:fe5cb0a8fc5a | 25 | |
dreamselec | 0:fe5cb0a8fc5a | 26 | MCP23017 *i2cport; |
dreamselec | 0:fe5cb0a8fc5a | 27 | WattBob_TextLCD *lcd; |
dreamselec | 0:fe5cb0a8fc5a | 28 | |
dreamselec | 2:7a55cb10259f | 29 | TCS3472_I2C rgb_sensor(p28, p27); |
dreamselec | 2:7a55cb10259f | 30 | Serial pc(USBTX, USBRX); |
dreamselec | 2:7a55cb10259f | 31 | |
dreamselec | 2:7a55cb10259f | 32 | Command myCommand; |
dreamselec | 2:7a55cb10259f | 33 | |
dreamselec | 2:7a55cb10259f | 34 | void initPort(){ |
dreamselec | 2:7a55cb10259f | 35 | myLED3 = 1; |
dreamselec | 2:7a55cb10259f | 36 | pc.baud(gBaudRate); |
dreamselec | 2:7a55cb10259f | 37 | pc.format(8, SerialBase::None, gStopBits); |
dreamselec | 2:7a55cb10259f | 38 | myLED4 = 1; |
dreamselec | 2:7a55cb10259f | 39 | wait (0.1); |
dreamselec | 2:7a55cb10259f | 40 | } |
dreamselec | 0:fe5cb0a8fc5a | 41 | |
dreamselec | 0:fe5cb0a8fc5a | 42 | int main(){ |
dreamselec | 0:fe5cb0a8fc5a | 43 | i2cport = new MCP23017(p9, p10, 0x40); |
dreamselec | 0:fe5cb0a8fc5a | 44 | lcd = new WattBob_TextLCD(i2cport); |
dreamselec | 2:7a55cb10259f | 45 | myLED1 = 1; |
dreamselec | 0:fe5cb0a8fc5a | 46 | BACKLIGHT_ON(i2cport); |
dreamselec | 2:7a55cb10259f | 47 | CLEAR_LCD(); |
dreamselec | 2:7a55cb10259f | 48 | LCDFL(); |
dreamselec | 2:7a55cb10259f | 49 | PRINT_LCD("Initilizing..."); |
dreamselec | 2:7a55cb10259f | 50 | myLED2 = 1; |
dreamselec | 2:7a55cb10259f | 51 | initPort(); |
dreamselec | 1:92a2a5ef65a8 | 52 | srand((unsigned)time(NULL)); |
dreamselec | 2:7a55cb10259f | 53 | U_LEDS_OFF(); |
dreamselec | 2:7a55cb10259f | 54 | CLEAR_LCD(); |
dreamselec | 2:7a55cb10259f | 55 | myLED1 = 1; |
dreamselec | 0:fe5cb0a8fc5a | 56 | |
dreamselec | 2:7a55cb10259f | 57 | FOREVER { |
dreamselec | 2:7a55cb10259f | 58 | Type type; |
dreamselec | 2:7a55cb10259f | 59 | do { |
dreamselec | 2:7a55cb10259f | 60 | type = listenForCommand(); |
dreamselec | 2:7a55cb10259f | 61 | } while (type != -1); |
dreamselec | 2:7a55cb10259f | 62 | recieveCommand(&myCommand, type); |
dreamselec | 2:7a55cb10259f | 63 | pc.printf("%s\r\n<%s>\r\n%s;\r\n", myCommand.commandType, myCommand.commandObject, myCommand.commandString); |
dreamselec | 2:7a55cb10259f | 64 | decodeCommand(&myCommand); |
dreamselec | 2:7a55cb10259f | 65 | |
dreamselec | 2:7a55cb10259f | 66 | |
dreamselec | 2:7a55cb10259f | 67 | } |
dreamselec | 0:fe5cb0a8fc5a | 68 | } |