56
56
#define PANIC_DISTANCE 5 // Mix distance we red warning indication should be active (in cm)
57
57
#define PARKED_DISTANCE 20 // Distance when "parked signal" should be sent to controller (in cm)
58
58
59
+ #define PARK_OFF_TIMEOUT 20000 // Number of milliseconds until turning off light when parked.
60
+
59
61
// Note that for older NeoPixel strips you might need to change the third parameter--see the strandtest
60
62
// example for more information on possible values.
61
63
@@ -67,10 +69,11 @@ NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and
67
69
#define CHILD_ID 1
68
70
MySensor gw;
69
71
MyMessage msg (CHILD_ID,V_TRIPPED);
70
- int oldParkedStatus=- 1 ;
72
+ # endif
71
73
unsigned long sendInterval = 5000 ; // Send park status at maximum every 5 second.
72
74
unsigned long lastSend;
73
- #endif
75
+
76
+ int oldParkedStatus=-1 ;
74
77
75
78
unsigned long blinkInterval = 100 ; // blink interval (milliseconds)
76
79
unsigned long lastBlinkPeriod;
@@ -109,56 +112,63 @@ void loop() {
109
112
if (now-lastDebouncePeriod > distDebounce) {
110
113
lastDebouncePeriod = now;
111
114
112
- #ifdef SEND_STATUS_TO_CONTROLLER
113
115
// Update parked status
114
116
int parked = displayDist != 0 && displayDist<PARKED_DISTANCE;
115
117
if (parked != oldParkedStatus && now-lastSend > sendInterval) {
116
118
if (parked)
117
119
Serial.println (" Car Parked" );
118
120
else
119
121
Serial.println (" Car Gone" );
122
+ #ifdef SEND_STATUS_TO_CONTROLLER
120
123
gw.send (msg.set (parked));
124
+ #endif
121
125
oldParkedStatus = parked;
122
126
lastSend = now;
123
127
}
124
- #endif
125
-
126
- if (displayDist == 0 ) {
127
- // No reading from sensor, assume no object found
128
- numLightPixels--;
129
- } else {
130
- skipZero = 0 ;
131
- int newLightPixels = NUMPIXELS - (NUMPIXELS*(displayDist-PANIC_DISTANCE)/MAX_DISTANCE);
132
- if (newLightPixels>numLightPixels) {
133
- // Fast raise
134
- numLightPixels += max ((newLightPixels - numLightPixels) / 2 , 1 );
135
- } else if (newLightPixels<numLightPixels) {
136
- // Slow decent
137
- numLightPixels--;
138
- }
139
- }
140
128
141
- if (numLightPixels>=NUMPIXELS) {
142
- // Do some intense red blinking
143
- if (now-lastBlinkPeriod > blinkInterval) {
144
- blinkColor = !blinkColor;
145
- lastBlinkPeriod = now;
129
+ if (parked && now-lastSend > PARK_OFF_TIMEOUT) {
130
+ // We've been parked for a while now. Turn off all pixels
131
+ for (int i=0 ;i<NUMPIXELS;i++){
132
+ pixels.setPixelColor (i, pixels.Color (0 ,0 ,0 ));
146
133
}
147
- for (int i=0 ;i<numLightPixels;i++){
148
- pixels.setPixelColor (i, pixels.Color (blinkColor?255 *MAX_INTESITY/100 :0 ,0 ,0 ));
149
- }
150
134
} else {
151
- for (int i=0 ;i<numLightPixels;i++){
152
- int r = 255 * i/NUMPIXELS;
153
- int g = 255 - r;
154
- // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
155
- pixels.setPixelColor (i, pixels.Color (r*MAX_INTESITY/100 ,g*MAX_INTESITY/100 ,0 ));
135
+ if (displayDist == 0 ) {
136
+ // No reading from sensor, assume no object found
137
+ numLightPixels--;
138
+ } else {
139
+ skipZero = 0 ;
140
+ int newLightPixels = NUMPIXELS - (NUMPIXELS*(displayDist-PANIC_DISTANCE)/MAX_DISTANCE);
141
+ if (newLightPixels>numLightPixels) {
142
+ // Fast raise
143
+ numLightPixels += max ((newLightPixels - numLightPixels) / 2 , 1 );
144
+ } else if (newLightPixels<numLightPixels) {
145
+ // Slow decent
146
+ numLightPixels--;
147
+ }
156
148
}
157
- // Turn off the rest
158
- for (int i=numLightPixels;i<NUMPIXELS;i++){
159
- pixels.setPixelColor (i, pixels.Color (0 ,0 ,0 ));
149
+
150
+ if (numLightPixels>=NUMPIXELS) {
151
+ // Do some intense red blinking
152
+ if (now-lastBlinkPeriod > blinkInterval) {
153
+ blinkColor = !blinkColor;
154
+ lastBlinkPeriod = now;
155
+ }
156
+ for (int i=0 ;i<numLightPixels;i++){
157
+ pixels.setPixelColor (i, pixels.Color (blinkColor?255 *MAX_INTESITY/100 :0 ,0 ,0 ));
158
+ }
159
+ } else {
160
+ for (int i=0 ;i<numLightPixels;i++){
161
+ int r = 255 * i/NUMPIXELS;
162
+ int g = 255 - r;
163
+ // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
164
+ pixels.setPixelColor (i, pixels.Color (r*MAX_INTESITY/100 ,g*MAX_INTESITY/100 ,0 ));
165
+ }
166
+ // Turn off the rest
167
+ for (int i=numLightPixels;i<NUMPIXELS;i++){
168
+ pixels.setPixelColor (i, pixels.Color (0 ,0 ,0 ));
169
+ }
160
170
}
161
171
}
162
172
pixels.show (); // This sends the updated pixel color to the hardware.
163
173
}
164
- }
174
+ }
0 commit comments