Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: HCSR04 X_NUCLEO_6180XA1 mbed
Fork of HelloWorld_6180XA1 by
Diff: main.cpp
- Revision:
- 48:c577e2af2a10
- Parent:
- 47:04733a0905ba
- Child:
- 50:453855ed9372
diff -r 04733a0905ba -r c577e2af2a10 main.cpp
--- a/main.cpp Mon Mar 13 19:21:16 2017 +0000
+++ b/main.cpp Thu Apr 27 09:38:37 2017 +0000
@@ -15,6 +15,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
+#include "hcsr04.h"
/* Definitions ---------------------------------------------------------------*/
@@ -26,6 +27,12 @@
/* Variables -----------------------------------------------------------------*/
static XNucleo6180XA1 *board = NULL;
+float distance;
+
+
+HCSR04 UltrasonicSensor(PC_2,PC_3); //Trigger,Echo
+//Serial pc_serial(USBTX, USBRX); // tx, rx
+
/* Functions -----------------------------------------------------------------*/
@@ -37,6 +44,7 @@
int main()
{
int status;
+ pc.baud(921600);
uint32_t lux, dist;
DevI2C *device_i2c = new DevI2C(VL6180X_I2C_SDA, VL6180X_I2C_SCL);
@@ -53,6 +61,8 @@
while (true) {
board->sensor_top->get_distance(&dist);
board->sensor_top->get_lux(&lux);
- printf ("Distance: %d, Lux: %d\n\r", dist, lux);
+ distance = UltrasonicSensor.distance();
+ printf ("Time of Flight: %d, Lux: %d, Ultrasound: %d \n\r", dist, lux, (int)distance);
+ wait(0.01);
}
}
