Dependencies: X_NUCLEO_53L0A1 mbed
Fork of HelloWorld_53L0A1 by
Revision 13:d55d8159dd3c, committed 2018-03-26
- Comitter:
- kenken0721
- Date:
- Mon Mar 26 08:08:10 2018 +0000
- Parent:
- 12:e9dedf2d2560
- Commit message:
- ?
Changed in this revision
| X_NUCLEO_53L0A1.lib | Show annotated file Show diff for this revision Revisions of this file |
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/X_NUCLEO_53L0A1.lib Mon Dec 18 09:56:04 2017 +0000 +++ b/X_NUCLEO_53L0A1.lib Mon Mar 26 08:08:10 2018 +0000 @@ -1,1 +1,1 @@ -http://os.mbed.com/teams/ST/code/X_NUCLEO_53L0A1/#99c367e8a402 +https://os.mbed.com/users/kenken0721/code/X_NUCLEO_53L0A1/#fe8a6715a2da
--- a/main.cpp Mon Dec 18 09:56:04 2017 +0000
+++ b/main.cpp Mon Mar 26 08:08:10 2018 +0000
@@ -2,38 +2,50 @@
#include "XNucleo53L0A1.h"
#include <stdio.h>
-/* This VL53L0X Expansion board test application performs a range measurement in polling mode
- on the onboard embedded top sensor. */
-
-#define VL53L0_I2C_SDA D14
-#define VL53L0_I2C_SCL D15
+#define VL53L0_I2C_SDA D4
+#define VL53L0_I2C_SCL D5
static XNucleo53L0A1 *board=NULL;
+DigitalOut dout(D8);
+DigitalOut Led(D13);
+int count = 0;
-/*=================================== Main ==================================
-=============================================================================*/
-int main()
-{
- int status;
- uint32_t distance;
+int main(){
+ int status;
+ uint32_t distance = 0;
DevI2C *device_i2c = new DevI2C(VL53L0_I2C_SDA, VL53L0_I2C_SCL);
- /* creates the 53L0A1 expansion board singleton obj */
board = XNucleo53L0A1::instance(device_i2c, A2, D8, D2);
-
- /* init the 53L0A1 expansion board with default values */
status = board->init_board();
if (status) {
- printf("Failed to init board!\r\n");
return 0;
}
-
- while (1) {
+ dout = 0.0;
+ Led = 0.0;
+ while (1) {
status = board->sensor_centre->get_distance(&distance);
if (status == VL53L0X_ERROR_NONE) {
- printf("Distance : %ld\r\n", distance);
+ if(distance <= 100){
+ count++;
+ }else{
+ count--;
+ }
+ }else{
+ count--;
}
- }
+ if(count >= 20){
+ count = 20;
+ }else if(count <= -10){
+ count = -10;
+ }
+ if(count >= 10){
+ dout = 1.0;
+ Led = 1.0;
+ }else if(count <= 0){
+ dout = 0.0;
+ Led = 0.0;
+ }
+ }
}
