Check program for 6180XA1_simple lib.

Dependencies:   6180XA1_simple

Committer:
kenjiArai
Date:
Thu Feb 01 12:10:45 2018 +0000
Revision:
1:163bbf3bfc20
Parent:
0:91db3c5d99f6
modify for new library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kenjiArai 0:91db3c5d99f6 1 /*
kenjiArai 0:91db3c5d99f6 2 * Mbed Application program
kenjiArai 0:91db3c5d99f6 3 * Time-of-Flight ranging and gesture detection sensor / STMicro VL6180XA1
kenjiArai 0:91db3c5d99f6 4 * https://os.mbed.com/components/X-NUCLEO-6180XA1-Proximity-and-ambient-l/
kenjiArai 0:91db3c5d99f6 5 *
kenjiArai 0:91db3c5d99f6 6 * Strawberry Linux
kenjiArai 0:91db3c5d99f6 7 * https://strawberry-linux.com/catalog/items?code=16180
kenjiArai 0:91db3c5d99f6 8 *
kenjiArai 0:91db3c5d99f6 9 * -------- TESTED ONLY ON Strawberry board --------
kenjiArai 0:91db3c5d99f6 10 * With Nucleo-F446RE Mbed board
kenjiArai 0:91db3c5d99f6 11 *
kenjiArai 0:91db3c5d99f6 12 * Copyright (c) 2018 Kenji Arai / JH1PJL
kenjiArai 0:91db3c5d99f6 13 * http://www.page.sannet.ne.jp/kenjia/index.html
kenjiArai 0:91db3c5d99f6 14 * http://mbed.org/users/kenjiArai/
kenjiArai 0:91db3c5d99f6 15 * Created: January 25th, 2018
kenjiArai 1:163bbf3bfc20 16 * Revised: Feburary 1st, 2018
kenjiArai 0:91db3c5d99f6 17 */
kenjiArai 0:91db3c5d99f6 18
kenjiArai 0:91db3c5d99f6 19 /*
kenjiArai 0:91db3c5d99f6 20 If you switch MY_LOG definition zero to 1 in vl6180x_platform.h line 37,
kenjiArai 0:91db3c5d99f6 21 you may have a trouble for Serial class due to line order VL6180X.h file
kenjiArai 0:91db3c5d99f6 22 and Serial constractor!
kenjiArai 0:91db3c5d99f6 23 */
kenjiArai 0:91db3c5d99f6 24
kenjiArai 0:91db3c5d99f6 25 // Include --------------------------------------------------------------------
kenjiArai 0:91db3c5d99f6 26 #include "mbed.h"
kenjiArai 0:91db3c5d99f6 27 #include "VL6180X.h"
kenjiArai 0:91db3c5d99f6 28
kenjiArai 0:91db3c5d99f6 29 // Definition -----------------------------------------------------------------
kenjiArai 0:91db3c5d99f6 30
kenjiArai 0:91db3c5d99f6 31 // Constructor ----------------------------------------------------------------
kenjiArai 0:91db3c5d99f6 32 DigitalOut myled(LED1);
kenjiArai 0:91db3c5d99f6 33 Serial pc(USBTX, USBRX);
kenjiArai 1:163bbf3bfc20 34 I2C i2c(I2C_SDA, I2C_SCL);
kenjiArai 1:163bbf3bfc20 35 VL6180X sensor(i2c, D8);
kenjiArai 0:91db3c5d99f6 36 Timer t;
kenjiArai 0:91db3c5d99f6 37
kenjiArai 0:91db3c5d99f6 38
kenjiArai 0:91db3c5d99f6 39 // RAM ------------------------------------------------------------------------
kenjiArai 0:91db3c5d99f6 40
kenjiArai 0:91db3c5d99f6 41 // ROM / Constant data --------------------------------------------------------
kenjiArai 0:91db3c5d99f6 42
kenjiArai 0:91db3c5d99f6 43 // Function prototypes --------------------------------------------------------
kenjiArai 0:91db3c5d99f6 44
kenjiArai 0:91db3c5d99f6 45 //------------------------------------------------------------------------------
kenjiArai 0:91db3c5d99f6 46 // Control Program
kenjiArai 0:91db3c5d99f6 47 //------------------------------------------------------------------------------
kenjiArai 0:91db3c5d99f6 48 int main()
kenjiArai 0:91db3c5d99f6 49 {
kenjiArai 0:91db3c5d99f6 50 // int status = 0;
kenjiArai 0:91db3c5d99f6 51 uint32_t lux;
kenjiArai 0:91db3c5d99f6 52 uint32_t dist;
kenjiArai 0:91db3c5d99f6 53 uint32_t count = 0;
kenjiArai 0:91db3c5d99f6 54 uint32_t tm;
kenjiArai 0:91db3c5d99f6 55
kenjiArai 0:91db3c5d99f6 56 while (true) {
kenjiArai 0:91db3c5d99f6 57 t.reset();
kenjiArai 0:91db3c5d99f6 58 t.start();
kenjiArai 0:91db3c5d99f6 59 myled = !myled;
kenjiArai 0:91db3c5d99f6 60 sensor.get_distance(&dist);
kenjiArai 0:91db3c5d99f6 61 sensor.get_lux(&lux);
kenjiArai 0:91db3c5d99f6 62 pc.printf("Distance: %4d, Lux: %4d, ", dist, lux);
kenjiArai 0:91db3c5d99f6 63 tm = t.read_ms();
kenjiArai 0:91db3c5d99f6 64 wait_ms(200 - tm);
kenjiArai 0:91db3c5d99f6 65 pc.printf("Looptime: %4d, Count:%5d\r\n", t.read_ms(), count++);
kenjiArai 0:91db3c5d99f6 66 }
kenjiArai 0:91db3c5d99f6 67 }