// This #include statement was automatically added by the Spark IDE.
#include "OneWire.h"
// This #include statement was automatically added by the Spark IDE.
#include "spark-dallas-temperature.h"
#include <math.h>
int redPin = D1; // RED pin of the LED to PWM pin **A0**
int greenPin = D2; // GREEN pin of the LED to PWM pin **D0**
int bluePin = D3; // BLUE pin of the LED to PWM pin **D1**
int redValue = 255; // Full brightness for an ANODE RGB LED is 0, and off 255
int greenValue = 255; // Full brightness for an ANODE RGB LED is 0, and off 255
int blueValue = 255; // Full brightness for an ANODE RGB LED is 0, and off 255</td>
int buttonPin = D4;
// -----------------
// Read temperature
// -----------------
// Data wire is plugged into port 0 on the Arduino
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(D0 );
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature dallas(&oneWire);
// Create a variable that will store the temperature value
double temperature = 0.0;
double temperatureF = 0.0;
void setup()
{
// Register a Particle variable here
Particle.variable("temperature", &temperature, DOUBLE);
Particle.variable("temperatureF", &temperatureF, DOUBLE);
// setup the library
dallas.begin();
// Set up our RGB LED pins for output
pinMode( redPin, OUTPUT);
pinMode( greenPin, OUTPUT);
pinMode( bluePin, OUTPUT);
pinMode(buttonPin, INPUT_PULLUP);
Serial.begin( 9600 );
Serial.println( "My program is starting up ");
}
void setRGBColor( int r, int g, int b ){
redValue = r;
greenValue = g;
blueValue = b;
analogWrite(redPin, 255 - redValue);
analogWrite(greenPin, 255 - greenValue);
analogWrite(bluePin, 255 - blueValue);
}
void loop()
{
int buttonState = digitalRead(buttonPin);
if(buttonState == LOW ){
setRGBColor(255,255,0);
}
delay(2000);
dallas.requestTemperatures();
// get the temperature in Celcius
float tempC = dallas.getTempCByIndex(0);
// convert to double
temperature = (double)tempC;
// convert to Fahrenheit
float tempF = DallasTemperature::toFahrenheit( tempC );
// convert to double
temperatureF = (double)tempF;
if( digitalRead( buttonPin ) == LOW ){ Serial.println( temperatureF );
}
if( digitalRead( buttonPin )== LOW){ Particle.publish( String ( temperatureF ));
delay(500);
}
// Serial.print("The temperature in F is:");
// Serial.println( temperatureF );
if(temperatureF < 95.0){
setRGBColor(0,0,255);
}else if(temperatureF >= 75.0 && temperatureF <= 105.0){
setRGBColor(0,255,0);
}else{
setRGBColor(255,0,0);
}
delay(500);
}
Click to Expand
Content Rating
Is this a good/useful/informative piece of content to include in the project? Have your say!
You must login before you can post a comment. .