test

Dependencies:   S11059 VL6180X m3pi mbed

Fork of tc_agent by Ichiro Maruta

Committer:
maruta
Date:
Tue Jul 19 03:51:32 2016 +0000
Revision:
2:3ebca956fd36
Parent:
1:6340d62d759f
Child:
3:f1ddc26da601
sensor test

Who changed what in which revision?

UserRevisionLine numberNew contents of line
maruta 2:3ebca956fd36 1 #include "VL6180X.h"
sburg 0:2508f38e90fe 2 #include "mbed.h"
tennisbaca 1:6340d62d759f 3 #include "m3pi.h"
maruta 2:3ebca956fd36 4 #include "S11059.h"
sburg 0:2508f38e90fe 5
maruta 2:3ebca956fd36 6 VL6180x rf(p28, p27); //I2C sda and scl
sburg 0:2508f38e90fe 7 Serial pc(USBTX, USBRX); //USB serial
maruta 2:3ebca956fd36 8 S11059 col(p28,p27);
tennisbaca 1:6340d62d759f 9 m3pi m3pi;
tennisbaca 1:6340d62d759f 10 Timer t;
sburg 0:2508f38e90fe 11
sburg 0:2508f38e90fe 12 int main() {
tennisbaca 1:6340d62d759f 13 m3pi.cls();
tennisbaca 1:6340d62d759f 14 m3pi.locate(0,0);
tennisbaca 1:6340d62d759f 15 m3pi.printf("Sensor");
tennisbaca 1:6340d62d759f 16 m3pi.locate(0,1);
tennisbaca 1:6340d62d759f 17 m3pi.printf("Check");
tennisbaca 1:6340d62d759f 18 wait(1);
maruta 2:3ebca956fd36 19 int reading;
tennisbaca 1:6340d62d759f 20 float time[2];
tennisbaca 1:6340d62d759f 21 int bl=0;
tennisbaca 1:6340d62d759f 22 char buf[255];
maruta 2:3ebca956fd36 23 m3pi.cls();
maruta 2:3ebca956fd36 24 rf.VL6180xInit();
maruta 2:3ebca956fd36 25 rf.VL6180xDefautSettings();
tennisbaca 1:6340d62d759f 26
sburg 0:2508f38e90fe 27 while(1) {
tennisbaca 1:6340d62d759f 28 m3pi.cls();
tennisbaca 1:6340d62d759f 29 t.start();
tennisbaca 1:6340d62d759f 30 time[0] = t.read();
maruta 2:3ebca956fd36 31 rf.triggerDistance();
maruta 2:3ebca956fd36 32 reading = rf.pollDistance();
tennisbaca 1:6340d62d759f 33 t.stop();
tennisbaca 1:6340d62d759f 34 time[1] = t.read();
maruta 2:3ebca956fd36 35 col.update();
maruta 2:3ebca956fd36 36 bl = col.b;
tennisbaca 1:6340d62d759f 37 int len = 0;
maruta 2:3ebca956fd36 38 m3pi.locate(0,0);
maruta 2:3ebca956fd36 39 m3pi.printf("%dmm",reading);
maruta 2:3ebca956fd36 40
maruta 2:3ebca956fd36 41 // m3pi.locate(0,1);
maruta 2:3ebca956fd36 42 // m3pi.printf("%d",bl);
maruta 2:3ebca956fd36 43
tennisbaca 1:6340d62d759f 44 m3pi.locate(0,1);
maruta 2:3ebca956fd36 45 m3pi.printf("%.3fms",(time[1]-time[0])*1000);
maruta 2:3ebca956fd36 46
maruta 2:3ebca956fd36 47 pc.printf("Read %d mm\n\r", reading);
tennisbaca 1:6340d62d759f 48 m3pi.print(buf,len);
maruta 2:3ebca956fd36 49 wait_ms(100);
sburg 0:2508f38e90fe 50 }
sburg 0:2508f38e90fe 51 }