-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprojectBuild.ino
126 lines (88 loc) · 3 KB
/
projectBuild.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// This #include statement was automatically added by the Particle IDE.
#include <neopixel.h>
// This #include statement was automatically added by the Particle IDE.
#include <Adafruit_VL53L0X.h>
/*
* Project projectBuild
* Description:
* Author: Ekerin M.A.
* Date: start.6/15/2017
* Components
Adafruit:
- VL53L0X, Time of Flight Distance Sensor
- library added
- SPW2430, MEMS Microphone Breakout
- Neopixels
- library added
Amazon:
- Amazon Dot with Alexa Capabilites
*/
#define VL53L0X_LOG_ENABLE 0
uint32_t _trace_evel = TRACE_LEVEL_ALL;
#if defined(PARTICLE) && (SYSTEM_VERSION >= 0x00060000)
SerialLogHandler logHandler(LOG_LEVEL_ALL);
#endif
Adafruit_VL53L0X lox = Adafruit_VL53L0X();
int distVal = 0;
// IMPORTANT: Set pixel COUNT, PIN and TYPE
#define PIXEL_PIN D6
#define PIXEL_COUNT 1
#define PIXEL_TYPE WS2812B
Adafruit_NeoPixel strip(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
//int analogVal = 0;
// in this, analogVal is the distance from the distVal
int distValMapped = 0;
// in this, analogValMapped is the distVal mapped to the neopixel range
int counter = 0;
// Prototypes for local build, ok to leave in for Build IDE
// setup() runs once, when the device is first turned on.
void setup() {
// Put initialization like pinMode and begin functions here.
Serial.begin(115200);
Serial.println("Adafruit VL53L0X test");
if (!lox.begin()) {
Serial.println(F("Failed to boot VL53L0X"));
while(1);
}
Serial.println(F("VL53L0X API Simple Ranging example\n\n"));
Particle.variable("sensor", distVal);
strip.begin();
strip.show();
}
// loop() runs over and over again, as quickly as it can execute.
void loop() {
// The core of your code will likely live here.
strip.setPixelColor(1, 0, 255, 0);
VL53L0X_RangingMeasurementData_t measure;
Serial.print("Reading a measurement...");
lox.rangingTest(&measure, true); // pass in 'true' to et debug in data printout
distVal = measure.RangeMilliMeter;
//distVal= constrain(distVal, 10, 900);
/*if(measure.RangeMilliMeter < 10) {
distVal = 0;
strip.setBrightness
}
*/
/* if(measure.RangeMilliMeter > 900){
distVal = 900;
strip.setBrightness(0);
}
*/
if (distVal < 900) {
Serial.println("Distance (mm): " + measure.RangeMilliMeter); //Serial.println(measure.RangeMilliMeter);
Particle.publish("distance", String(distVal));
strip.setBrightness(distVal);
}
else {
Serial.println("No subject(s) witin range");
Particle.publish("No subject(s) within range");
strip.setBrightness(0);
}
//distValMapped = map(distVal, 0, 900, 255, 5);
Serial.println("distance: " + String(distVal)); //Serial.println( String(distVal));
Serial.println("seconds: " + String(Time.second())); //Serial.println(millis());
//strip.setBrightness(distValMapped);
Particle.publish("mapped distance value", distValMapped);
Serial.println("brightness: " + String(strip.getBrightness())); //Serial.println(String(strip.getBrightness()));
delay(10);
}