Ultrasound sensor and IMU combined

Dependencies:   HCSR04 X_NUCLEO_6180XA1 mbed

Fork of HelloWorld_6180XA1 by ST

main.cpp

Committer:
EmbeddedSam
Date:
2017-04-27
Revision:
48:c577e2af2a10
Parent:
47:04733a0905ba
Child:
50:453855ed9372

File content as of revision 48:c577e2af2a10:

/*
   This VL6180X Expansion board test application performs a range measurement
   and als measurement in polling mode on the onboard embedded top sensor. 
   The result of both the measures are printed on the serial over.  
   get_distance() and get_lux() are synchronous! They block the caller until the
   result will be ready.
*/


/* Includes ------------------------------------------------------------------*/

#include "mbed.h"
#include "XNucleo6180XA1.h"
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include "hcsr04.h"


/* Definitions ---------------------------------------------------------------*/

#define VL6180X_I2C_SDA   D14 
#define VL6180X_I2C_SCL   D15 


/* Variables -----------------------------------------------------------------*/

static XNucleo6180XA1 *board = NULL;
float distance;


HCSR04 UltrasonicSensor(PC_2,PC_3); //Trigger,Echo 
//Serial pc_serial(USBTX, USBRX); // tx, rx



/* Functions -----------------------------------------------------------------*/

/*=================================== Main ==================================
  Prints on the serial over USB the measured distance and lux.
  The measures are run in single shot polling mode.
=============================================================================*/
int main()
{ 
	int status;
	pc.baud(921600);
	uint32_t lux, dist;
	DevI2C *device_i2c = new DevI2C(VL6180X_I2C_SDA, VL6180X_I2C_SCL);

	/* Creates the 6180XA1 expansion board singleton obj. */
	board = XNucleo6180XA1::instance(device_i2c, A3, A2, D13, D2);

	/* Initializes the 6180XA1 expansion board with default values. */
	status = board->init_board();
	if (status) {
		printf("Failed to init board!\n\r");
		return 0;
	}

	while (true) {
		board->sensor_top->get_distance(&dist);
		board->sensor_top->get_lux(&lux);
		distance = UltrasonicSensor.distance();
		printf ("Time of Flight: %d, Lux: %d, Ultrasound: %d \n\r", dist, lux, (int)distance);    
        wait(0.01);
	}
}