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.
Fork of HelloWorld_53L0A1 by
main.cpp@10:76e86ff6e9bf, 2017-02-01 (annotated)
- Committer:
- zero515
- Date:
- Wed Feb 01 16:41:29 2017 +0000
- Revision:
- 10:76e86ff6e9bf
- Parent:
- 9:fd46a7024326
test3;
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| johnAlexander | 0:ce8359133ae6 | 1 | #include "mbed.h" |
| johnAlexander | 0:ce8359133ae6 | 2 | #include "x_nucleo_53l0a1.h" |
| johnAlexander | 0:ce8359133ae6 | 3 | #include <stdio.h> |
| johnAlexander | 0:ce8359133ae6 | 4 | |
| zero515 | 6:bc6c3c8c9976 | 5 | #define VL53L0_I2C_SDA D4 |
| zero515 | 6:bc6c3c8c9976 | 6 | #define VL53L0_I2C_SCL D5 |
| johnAlexander | 0:ce8359133ae6 | 7 | |
| johnAlexander | 0:ce8359133ae6 | 8 | static X_NUCLEO_53L0A1 *board=NULL; |
| zero515 | 6:bc6c3c8c9976 | 9 | Serial pc(USBTX, USBRX); |
| zero515 | 9:fd46a7024326 | 10 | Serial pc2(D1,D0); |
| zero515 | 9:fd46a7024326 | 11 | |
| zero515 | 9:fd46a7024326 | 12 | |
| zero515 | 9:fd46a7024326 | 13 | DigitalOut myled(LED1); |
| johnAlexander | 1:3483e701ec59 | 14 | |
| johnAlexander | 0:ce8359133ae6 | 15 | |
| johnAlexander | 0:ce8359133ae6 | 16 | int main() |
| johnAlexander | 0:ce8359133ae6 | 17 | { |
| zero515 | 8:5f1b4151c9e4 | 18 | int status,i,add,ds[12]; |
| johnAlexander | 4:c8932fb926d6 | 19 | uint32_t distance; |
| zero515 | 6:bc6c3c8c9976 | 20 | pc.baud(115200); |
| zero515 | 9:fd46a7024326 | 21 | pc2.baud(115200); |
| johnAlexander | 3:b3f70617a6b3 | 22 | |
| johnAlexander | 4:c8932fb926d6 | 23 | DevI2C *device_i2c =new DevI2C(VL53L0_I2C_SDA, VL53L0_I2C_SCL); |
| johnAlexander | 4:c8932fb926d6 | 24 | |
| johnAlexander | 4:c8932fb926d6 | 25 | board=X_NUCLEO_53L0A1::Instance(device_i2c, A2, D8, D2); |
| johnAlexander | 3:b3f70617a6b3 | 26 | |
| johnAlexander | 4:c8932fb926d6 | 27 | status=board->InitBoard(); |
| zero515 | 8:5f1b4151c9e4 | 28 | |
| zero515 | 8:5f1b4151c9e4 | 29 | for(i = 0; i <= 10; i++) { |
| zero515 | 8:5f1b4151c9e4 | 30 | ds[i] = 0; |
| zero515 | 8:5f1b4151c9e4 | 31 | } |
| zero515 | 9:fd46a7024326 | 32 | myled = 1; |
| johnAlexander | 4:c8932fb926d6 | 33 | while(1) |
| johnAlexander | 4:c8932fb926d6 | 34 | { |
| zero515 | 9:fd46a7024326 | 35 | for(i = 0; i <= 2; i++) { |
| zero515 | 8:5f1b4151c9e4 | 36 | ds[i] = ds [i+1]; |
| zero515 | 8:5f1b4151c9e4 | 37 | } |
| johnAlexander | 4:c8932fb926d6 | 38 | status = board->sensor_centre->GetDistance(&distance); |
| zero515 | 9:fd46a7024326 | 39 | ds[2] = distance; |
| zero515 | 9:fd46a7024326 | 40 | if(ds[2] == 0){ |
| zero515 | 9:fd46a7024326 | 41 | ds[2] = ds[1]; |
| zero515 | 8:5f1b4151c9e4 | 42 | } |
| zero515 | 9:fd46a7024326 | 43 | for(i = 0; i <= 2; i++) { |
| zero515 | 8:5f1b4151c9e4 | 44 | add = ds[i] + add; |
| zero515 | 8:5f1b4151c9e4 | 45 | } |
| zero515 | 9:fd46a7024326 | 46 | add = add/30; |
| zero515 | 9:fd46a7024326 | 47 | |
| zero515 | 9:fd46a7024326 | 48 | pc.printf("pc%03d\r\n", add); |
| zero515 | 9:fd46a7024326 | 49 | pc2.printf("a%03d", add); |
| zero515 | 9:fd46a7024326 | 50 | |
| zero515 | 9:fd46a7024326 | 51 | |
| zero515 | 9:fd46a7024326 | 52 | if(add > 4) |
| zero515 | 9:fd46a7024326 | 53 | { |
| zero515 | 9:fd46a7024326 | 54 | myled = 1; |
| zero515 | 9:fd46a7024326 | 55 | } |
| zero515 | 9:fd46a7024326 | 56 | else |
| zero515 | 9:fd46a7024326 | 57 | { |
| zero515 | 9:fd46a7024326 | 58 | myled = 0; |
| zero515 | 9:fd46a7024326 | 59 | } |
| johnAlexander | 4:c8932fb926d6 | 60 | } |
| johnAlexander | 4:c8932fb926d6 | 61 | |
| johnAlexander | 0:ce8359133ae6 | 62 | } |
| johnAlexander | 0:ce8359133ae6 | 63 |
