system project / Mbed OS tof100

Dependencies:   MCP23017 VL6180 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 "stdint.h"
00003 #include "MCP23017.h"
00004 #include "WattBob_TextLCD.h"
00005 #include "VL6180.h"
00006 
00007 //Hyperterminal configuration
00008 //9600 bauds, 8-bit data, no parity
00009 
00010 //VL6180X defines
00011 
00012 
00013 #define IDENTIFICATIONMODEL_ID 0x0000
00014 
00015 
00016 Serial    pc(USBTX, USBRX);
00017 VL6180  TOF_sensor(p28, p27);
00018 
00019 DigitalOut myled(LED1);
00020 
00021 #define     BACK_LIGHT_ON(INTERFACE)    INTERFACE->write_bit(1,BL_BIT)
00022 #define     BACK_LIGHT_OFF(INTERFACE)   INTERFACE->write_bit(0,BL_BIT)
00023 
00024 MCP23017            *par_port;
00025 WattBob_TextLCD     *lcd;
00026 
00027 int main()
00028 {
00029     uint8_t dist;
00030     
00031     TOF_sensor.VL6180_Init();
00032     par_port = new MCP23017(p9, p10, 0x40);
00033     par_port->config(0x0F00, 0x0F00, 0x0F00);           // configure MCP23017 chip on WattBob
00034 
00035     lcd = new WattBob_TextLCD(par_port);
00036 
00037     BACK_LIGHT_ON(par_port);
00038     lcd->printf("TOF sensor");
00039     wait(3);
00040     lcd->cls(); lcd->locate(0,0);
00041 
00042     for(;;) {
00043         dist = TOF_sensor.getDistance();
00044         lcd->printf("d=%d", dist);
00045         wait(0.5);
00046         lcd->cls(); lcd->locate(0,0);
00047     }
00048 }