![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
dddddddddddddd
Dependencies: mbed TCS3472_I2C MCP23017 WattBob_TextLCD
main.cpp@0:220b16634543, 2020-03-03 (annotated)
- Committer:
- maazshaikh
- Date:
- Tue Mar 03 19:25:29 2020 +0000
- Revision:
- 0:220b16634543
dsd
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
maazshaikh | 0:220b16634543 | 1 | #include "mbed.h" |
maazshaikh | 0:220b16634543 | 2 | #include "MCP23017.h" |
maazshaikh | 0:220b16634543 | 3 | #include "WattBob_TextLCD.h" |
maazshaikh | 0:220b16634543 | 4 | #include "TCS3472_I2C.h" |
maazshaikh | 0:220b16634543 | 5 | |
maazshaikh | 0:220b16634543 | 6 | DigitalOut myled(LED1); |
maazshaikh | 0:220b16634543 | 7 | |
maazshaikh | 0:220b16634543 | 8 | #define BACK_LIGHT_ON(INTERFACE) INTERFACE->write_bit(1,BL_BIT) |
maazshaikh | 0:220b16634543 | 9 | #define BACK_LIGHT_OFF(INTERFACE) INTERFACE->write_bit(0,BL_BIT) |
maazshaikh | 0:220b16634543 | 10 | |
maazshaikh | 0:220b16634543 | 11 | MCP23017 *par_port; |
maazshaikh | 0:220b16634543 | 12 | WattBob_TextLCD *lcd; |
maazshaikh | 0:220b16634543 | 13 | |
maazshaikh | 0:220b16634543 | 14 | TCS3472_I2C rgb_sensor(p22, p21); |
maazshaikh | 0:220b16634543 | 15 | |
maazshaikh | 0:220b16634543 | 16 | Serial pc(USBTX, USBRX); // default 9600 baud |
maazshaikh | 0:220b16634543 | 17 | |
maazshaikh | 0:220b16634543 | 18 | int main() { |
maazshaikh | 0:220b16634543 | 19 | |
maazshaikh | 0:220b16634543 | 20 | int rgb_readings[4]; |
maazshaikh | 0:220b16634543 | 21 | |
maazshaikh | 0:220b16634543 | 22 | par_port = new MCP23017(p9, p10, 0x40); |
maazshaikh | 0:220b16634543 | 23 | par_port->config(0x0F00, 0x0F00, 0x0F00); // configure MCP23017 chip on WattBob |
maazshaikh | 0:220b16634543 | 24 | |
maazshaikh | 0:220b16634543 | 25 | lcd = new WattBob_TextLCD(par_port); |
maazshaikh | 0:220b16634543 | 26 | |
maazshaikh | 0:220b16634543 | 27 | BACK_LIGHT_ON(par_port); |
maazshaikh | 0:220b16634543 | 28 | lcd->printf("Colour sensor \n"); |
maazshaikh | 0:220b16634543 | 29 | |
maazshaikh | 0:220b16634543 | 30 | rgb_sensor.enablePowerAndRGBC(); |
maazshaikh | 0:220b16634543 | 31 | rgb_sensor.setIntegrationTime(100); |
maazshaikh | 0:220b16634543 | 32 | |
maazshaikh | 0:220b16634543 | 33 | myled = 0; |
maazshaikh | 0:220b16634543 | 34 | |
maazshaikh | 0:220b16634543 | 35 | for (int i = 0 ; i < 10 ; i++) { |
maazshaikh | 0:220b16634543 | 36 | rgb_sensor.getAllColors(rgb_readings); |
maazshaikh | 0:220b16634543 | 37 | pc.printf("red %d, green: %d, blue: %d, clear: %d\r\n",rgb_readings[0], rgb_readings[1], rgb_readings[2],rgb_readings[3]); |
maazshaikh | 0:220b16634543 | 38 | lcd->cls(); lcd->locate(0,0); |
maazshaikh | 0:220b16634543 | 39 | lcd->printf("clear: %d",rgb_readings[0], rgb_readings[1], rgb_readings[2],rgb_readings[3]); |
maazshaikh | 0:220b16634543 | 40 | wait(2); |
maazshaikh | 0:220b16634543 | 41 | lcd->cls(); lcd->locate(0,0); |
maazshaikh | 0:220b16634543 | 42 | lcd->printf("red: %d",rgb_readings[1]); |
maazshaikh | 0:220b16634543 | 43 | wait(2); |
maazshaikh | 0:220b16634543 | 44 | lcd->cls(); lcd->locate(0,0); |
maazshaikh | 0:220b16634543 | 45 | lcd->printf("green: %d",rgb_readings[2]); |
maazshaikh | 0:220b16634543 | 46 | wait(2); |
maazshaikh | 0:220b16634543 | 47 | lcd->cls(); lcd->locate(0,0); |
maazshaikh | 0:220b16634543 | 48 | lcd->printf("blue: %d",rgb_readings[3]); |
maazshaikh | 0:220b16634543 | 49 | wait(2); |
maazshaikh | 0:220b16634543 | 50 | } |
maazshaikh | 0:220b16634543 | 51 | } |