![](/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
Diff: main.cpp
- Revision:
- 2:7a55cb10259f
- Parent:
- 1:92a2a5ef65a8
- Child:
- 3:843b830ee8bd
--- a/main.cpp Thu Oct 29 15:19:24 2015 +0000 +++ b/main.cpp Fri Oct 30 07:51:47 2015 +0000 @@ -4,6 +4,9 @@ #include "MCP23017.h" #include <string> #include <time.h> +//#include <future> +#include "globals.h" +#include "commander.h" #define BACKLIGHT_ON(INTERFACE) INTERFACE->write_bit(1, 4); #define BACKLIGHT_OFF(INTERFACE) INTERFACE->write_bit(0, 4); @@ -12,22 +15,54 @@ #define CLEAR_LCD() lcd->cls(); #define LCDFL() lcd->locate(0,0); #define LCDSL() lcd->locate(1,0); -#define CLEAR_LEDS() i2cport->write_bit(0, 12); i2cport->write_bit(0, 13); i2cport->write_bit(0, 14); i2cport->write_bit(0, 15); +#define D_LEDS_OFF() i2cport->write_bit(0, 12); i2cport->write_bit(0, 13); i2cport->write_bit(0, 14); i2cport->write_bit(0, 15); +#define U_LEDS_OFF() myLED1 = 0; myLED2 = 0; myLED3 = 0; myLED4 = 0; -DigitalOut myled(LED1); +DigitalOut myLED1(LED1); +DigitalOut myLED2(LED2); +DigitalOut myLED3(LED3); +DigitalOut myLED4(LED4); MCP23017 *i2cport; WattBob_TextLCD *lcd; - TCS3472_I2C rgb_sensor(p28, p27); - Serial pc(USBTX, USBRX); +TCS3472_I2C rgb_sensor(p28, p27); +Serial pc(USBTX, USBRX); + +Command myCommand; + +void initPort(){ + myLED3 = 1; + pc.baud(gBaudRate); + pc.format(8, SerialBase::None, gStopBits); + myLED4 = 1; + wait (0.1); +} int main(){ i2cport = new MCP23017(p9, p10, 0x40); lcd = new WattBob_TextLCD(i2cport); + myLED1 = 1; BACKLIGHT_ON(i2cport); - int rgb_results[4]; - pc.baud(19200); + CLEAR_LCD(); + LCDFL(); + PRINT_LCD("Initilizing..."); + myLED2 = 1; + initPort(); srand((unsigned)time(NULL)); + U_LEDS_OFF(); + CLEAR_LCD(); + myLED1 = 1; + FOREVER { + Type type; + do { + type = listenForCommand(); + } while (type != -1); + recieveCommand(&myCommand, type); + pc.printf("%s\r\n<%s>\r\n%s;\r\n", myCommand.commandType, myCommand.commandObject, myCommand.commandString); + decodeCommand(&myCommand); + + + } } \ No newline at end of file