Skip to content

Commit

Permalink
Move some global variables to constants
Browse files Browse the repository at this point in the history
It's a best practise to declare pins as constants as these won't change
at runtime. This change does that and adds come comments to describe
what each does.
  • Loading branch information
forkata committed Oct 23, 2021
1 parent 2c053a7 commit 55561b6
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions temperature.ino
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,24 @@
#include <sstream>
#include <cstring>

// Init Dallas on pin 6
int temperatureSensor = D6;
// Init Dallas one-wire temperature sensors on pin 6.
const int TEMPERATURE_SENSOR_PIN = D6;

// The on-board LED is on pin 7
int led = D7;
// The on-board LED is on pin 7.
const int LED_PIN = D7;

DallasTemperature dallas(new OneWire(temperatureSensor));
const int DALLAS_RESOLUTION = 12;

int numberOfDevices;
// Wait 60 sec between loop itterations.
const int LOOP_DELAY = 60000;

DallasTemperature dallas(new OneWire(TEMPERATURE_SENSOR_PIN));

#define DALLAS_RESOLUTION 12
// The number of temperature sensors detected on the one-wire pin.
int numberOfDevices;

void setup(){
pinMode(led, OUTPUT);
pinMode(LED_PIN, OUTPUT);

numberOfDevices = 0;

Expand All @@ -33,7 +37,7 @@ void setup(){

void loop(){
// Turn LED On
digitalWrite(led, HIGH);
digitalWrite(LED_PIN, HIGH);

dallas.requestTemperatures();

Expand Down Expand Up @@ -96,8 +100,7 @@ void loop(){
Particle.publish("temperature", data, PRIVATE);

// Turn the LED Off
digitalWrite(led, LOW);
digitalWrite(LED_PIN, LOW);

// Wait 60 sec before repeating
delay(60000);
delay(LOOP_DELAY);
}

0 comments on commit 55561b6

Please sign in to comment.