system project / Mbed 2 deprecated gaasgjdvas

Dependencies:   mbed TCS3472_I2C MCP23017 WattBob_TextLCD

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "MCP23017.h"
00003 #include "WattBob_TextLCD.h"
00004 #include "TCS3472_I2C.h"
00005 
00006 DigitalOut myled(LED1);
00007 
00008 #define     BACK_LIGHT_ON(INTERFACE)    INTERFACE->write_bit(1,BL_BIT)
00009 #define     BACK_LIGHT_OFF(INTERFACE)   INTERFACE->write_bit(0,BL_BIT)
00010 
00011 MCP23017            *par_port;
00012 WattBob_TextLCD     *lcd;
00013 
00014 TCS3472_I2C rgb_sensor(p22, p21);
00015 
00016 Serial      pc(USBTX, USBRX);  // default 9600 baud
00017 
00018 int main() {
00019     
00020 int rgb_readings[4];
00021     
00022     par_port = new MCP23017(p9, p10, 0x40);
00023     par_port->config(0x0F00, 0x0F00, 0x0F00);           // configure MCP23017 chip on WattBob
00024 
00025     lcd = new WattBob_TextLCD(par_port);
00026 
00027     BACK_LIGHT_ON(par_port);
00028     lcd->printf("Colour sensor \n");
00029     
00030     rgb_sensor.enablePowerAndRGBC();
00031     rgb_sensor.setIntegrationTime(100);
00032     
00033     myled = 0;
00034     
00035     for (int i = 0 ; i < 10 ; i++) {
00036         rgb_sensor.getAllColors(rgb_readings);
00037         pc.printf("red  %d,  green: %d,  blue: %d,  clear: %d\r\n",rgb_readings[0], rgb_readings[1], rgb_readings[2],rgb_readings[3]);
00038         lcd->cls(); lcd->locate(0,0);
00039         lcd->printf("clear: %d",rgb_readings[0], rgb_readings[1], rgb_readings[2],rgb_readings[3]);
00040         wait(2);
00041         lcd->cls(); lcd->locate(0,0);
00042         lcd->printf("red: %d",rgb_readings[1]);
00043         wait(2);
00044         lcd->cls(); lcd->locate(0,0);
00045         lcd->printf("green:  %d",rgb_readings[2]);
00046         wait(2);
00047         lcd->cls(); lcd->locate(0,0);
00048         lcd->printf("blue: %d",rgb_readings[3]);
00049         wait(2);
00050     }
00051 }