99#include < seesaw_servo.h>
1010#include < seesaw_motor.h>
1111#include < seesaw_neopixel.h>
12-
12+
1313#define NEOPIX_PIN (20 ) /* Neopixel pin */
1414#define NEOPIX_NUMBER_OF_PIXELS (7 )
1515#define LUX CRICKIT_SIGNAL1
@@ -49,14 +49,14 @@ seesaw_NeoPixel strip = seesaw_NeoPixel(NEOPIX_NUMBER_OF_PIXELS, NEOPIX_PIN, NEO
4949#define MQTTled5 " house/led/five"
5050#define MQTTled5Bright " house/led/five/brightness"
5151#define MQTTled5Color " house/led/five/color"
52- // ***** Light Level Sensor
52+ // ***** Light Level Sensor
5353#define MQTTlux " house/lux"
54- // ***** Temperature and Humidity Sensor
54+ // ***** Temperature and Humidity Sensor
5555#define MQTTtemp " house/temperature"
5656#define MQTThumid " house/humidity"
57- // ***** Motion Sensor
57+ // ***** Motion Sensor
5858#define MQTTpir " house/motion"
59- // ***** Door Sensor
59+ // ***** Door Sensor
6060#define MQTTdoor " house/door"
6161
6262// ****************************** Connection Settings
@@ -100,7 +100,7 @@ void setup() {
100100 crickit.pinMode (LUX, INPUT);
101101 crickit.pinMode (PIR, INPUT_PULLUP);
102102 crickit.pinMode (DOOR, INPUT_PULLUP);
103-
103+
104104 myservo.attach (CRICKIT_SERVO1); // attaches the servo to CRICKIT_SERVO1 pin
105105 motor_a.attach (CRICKIT_MOTOR_A1, CRICKIT_MOTOR_A2);
106106 strip.begin (); // INITIALIZE NeoPixel strip object (REQUIRED)
@@ -153,7 +153,7 @@ void callback(char* topic, byte* payload, unsigned int length) {
153153 StrPayload = String (message_buff);
154154 int IntPayload = StrPayload.toInt ();
155155 Serial.print (StrPayload);
156-
156+
157157 if (String (topic) == MQTTlock) {
158158 if (StrPayload == " UNLOCK" ) {
159159 myservo.write (180 );
@@ -236,7 +236,7 @@ void callback(char* topic, byte* payload, unsigned int length) {
236236 strip.setPixelColor (1 , strip.Color (R[1 ], G[1 ], B[1 ]));
237237 }
238238 strip.show ();
239-
239+
240240 // .................. Light 3 ......................//
241241 if (String (topic) == MQTTled3) {
242242 if (StrPayload == " OFF" ) {
@@ -263,7 +263,7 @@ void callback(char* topic, byte* payload, unsigned int length) {
263263 strip.setPixelColor (2 , strip.Color (R[2 ], G[2 ], B[2 ]));
264264 }
265265 strip.show ();
266-
266+
267267// .................. Light 4 ......................//
268268 if (String (topic) == MQTTled4) {
269269 if (StrPayload == " OFF" ) {
@@ -290,7 +290,7 @@ void callback(char* topic, byte* payload, unsigned int length) {
290290 strip.setPixelColor (3 , strip.Color (R[3 ], G[3 ], B[3 ]));
291291 }
292292 strip.show ();
293-
293+
294294// .................. Light 5 ......................//
295295 if (String (topic) == MQTTled5) {
296296 if (StrPayload == " OFF" ) {
@@ -359,7 +359,7 @@ void reconnect() {
359359 client.subscribe (MQTTled5);
360360 client.subscribe (MQTTled5Bright);
361361 client.subscribe (MQTTled5Color);
362-
362+
363363 } else {
364364 Serial.print (" failed, rc=" );
365365 Serial.print (client.state ());
@@ -384,9 +384,9 @@ void loop() {
384384 if (!client.connected ()) {
385385 reconnect ();
386386 }
387-
387+
388388 // ************** Lux Smoothing
389-
389+
390390 total = total - lux_R[readIndex]; // subtract the last reading
391391 lux_R[readIndex] = crickit.analogRead (LUX); // read from the sensor
392392 total = total + lux_R[readIndex]; // add the reading to the total
@@ -400,7 +400,7 @@ void loop() {
400400 Serial.print (" Lux = " );
401401 Serial.println (Lux_A);
402402
403- snprintf (msg, 75 , " %ld " , Lux_A);
403+ snprintf (msg, 75 , " %d " , Lux_A);
404404 Serial.println (msg);
405405 client.publish (MQTTlux, msg);
406406
@@ -412,7 +412,7 @@ void loop() {
412412 Serial.println (" Motion Sensor = STILL" );
413413 client.publish (MQTTpir, " STILL" );
414414 }
415- delay (10 );
415+ delay (10 );
416416 if (crickit.digitalRead (DOOR)){
417417 Serial.println (" Door = OPEN" );
418418 client.publish (MQTTdoor, " OPEN" );
@@ -421,7 +421,7 @@ void loop() {
421421 client.publish (MQTTdoor, " CLOSED" );
422422 }
423423 }
424- delay (10 ); // delay in between reads for stability
424+ delay (10 ); // delay in between reads for stability
425425 client.loop ();
426426}
427427
0 commit comments