![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
n k
Dependencies: MCP23017 VL6180 WattBob_TextLCD
main.cpp@0:91d322e0261e, 2020-02-27 (annotated)
- Committer:
- maazshaikh
- Date:
- Thu Feb 27 12:29:46 2020 +0000
- Revision:
- 0:91d322e0261e
you have to be serious in your love
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
maazshaikh | 0:91d322e0261e | 1 | #include "mbed.h" |
maazshaikh | 0:91d322e0261e | 2 | #include "stdint.h" |
maazshaikh | 0:91d322e0261e | 3 | #include "MCP23017.h" |
maazshaikh | 0:91d322e0261e | 4 | #include "WattBob_TextLCD.h" |
maazshaikh | 0:91d322e0261e | 5 | #include "VL6180.h" |
maazshaikh | 0:91d322e0261e | 6 | |
maazshaikh | 0:91d322e0261e | 7 | //Hyperterminal configuration |
maazshaikh | 0:91d322e0261e | 8 | //9600 bauds, 8-bit data, no parity |
maazshaikh | 0:91d322e0261e | 9 | |
maazshaikh | 0:91d322e0261e | 10 | //VL6180X defines |
maazshaikh | 0:91d322e0261e | 11 | |
maazshaikh | 0:91d322e0261e | 12 | |
maazshaikh | 0:91d322e0261e | 13 | #define IDENTIFICATIONMODEL_ID 0x0000 |
maazshaikh | 0:91d322e0261e | 14 | |
maazshaikh | 0:91d322e0261e | 15 | |
maazshaikh | 0:91d322e0261e | 16 | Serial pc(USBTX, USBRX); |
maazshaikh | 0:91d322e0261e | 17 | VL6180 TOF_sensor(p28, p27); |
maazshaikh | 0:91d322e0261e | 18 | |
maazshaikh | 0:91d322e0261e | 19 | DigitalOut myled(LED1); |
maazshaikh | 0:91d322e0261e | 20 | |
maazshaikh | 0:91d322e0261e | 21 | #define BACK_LIGHT_ON(INTERFACE) INTERFACE->write_bit(1,BL_BIT) |
maazshaikh | 0:91d322e0261e | 22 | #define BACK_LIGHT_OFF(INTERFACE) INTERFACE->write_bit(0,BL_BIT) |
maazshaikh | 0:91d322e0261e | 23 | |
maazshaikh | 0:91d322e0261e | 24 | MCP23017 *par_port; |
maazshaikh | 0:91d322e0261e | 25 | WattBob_TextLCD *lcd; |
maazshaikh | 0:91d322e0261e | 26 | |
maazshaikh | 0:91d322e0261e | 27 | int main() |
maazshaikh | 0:91d322e0261e | 28 | { |
maazshaikh | 0:91d322e0261e | 29 | uint8_t dist; |
maazshaikh | 0:91d322e0261e | 30 | |
maazshaikh | 0:91d322e0261e | 31 | TOF_sensor.VL6180_Init(); |
maazshaikh | 0:91d322e0261e | 32 | par_port = new MCP23017(p9, p10, 0x40); |
maazshaikh | 0:91d322e0261e | 33 | par_port->config(0x0F00, 0x0F00, 0x0F00); // configure MCP23017 chip on WattBob |
maazshaikh | 0:91d322e0261e | 34 | |
maazshaikh | 0:91d322e0261e | 35 | lcd = new WattBob_TextLCD(par_port); |
maazshaikh | 0:91d322e0261e | 36 | |
maazshaikh | 0:91d322e0261e | 37 | BACK_LIGHT_ON(par_port); |
maazshaikh | 0:91d322e0261e | 38 | lcd->printf("TOF sensor"); |
maazshaikh | 0:91d322e0261e | 39 | wait(3); |
maazshaikh | 0:91d322e0261e | 40 | lcd->cls(); lcd->locate(0,0); |
maazshaikh | 0:91d322e0261e | 41 | |
maazshaikh | 0:91d322e0261e | 42 | for(;;) { |
maazshaikh | 0:91d322e0261e | 43 | dist = TOF_sensor.getDistance(); |
maazshaikh | 0:91d322e0261e | 44 | lcd->printf("d=%d", dist); |
maazshaikh | 0:91d322e0261e | 45 | wait(0.5); |
maazshaikh | 0:91d322e0261e | 46 | lcd->cls(); lcd->locate(0,0); |
maazshaikh | 0:91d322e0261e | 47 | } |
maazshaikh | 0:91d322e0261e | 48 | } |