#include "OneWire.h"
#include "spark-dallas-temperature.h"
#include <math.h>
OneWire oneWire( D0 );
DallasTemperature dallas( &oneWire );
double temperature = 0.0;
double temperatureF = 0.0;
int currenttime = 0;
int currentmin = 0;
int buttonPin = D1;
int redPin = A0;
int greenPin = D2;
int bluePin = D3;
int photoResistorCheckTime = 60000;
int lastPhotoResistorReport;
void setup()
{
Particle.variable( "temperature", &temperature, DOUBLE );
Particle.variable( "temperatureF", &temperatureF, DOUBLE );
Particle.variable( "time", ¤ttime, INT );
Particle.variable( "min",¤tmin, INT );
pinMode( redPin, OUTPUT);
pinMode( greenPin, OUTPUT);
pinMode( bluePin, OUTPUT);
pinMode( buttonPin, INPUT_PULLUP );
dallas.begin();
Serial.begin( 9600 );
lastPhotoResistorReport = millis();
}
void loop()
{
int buttonState = digitalRead( buttonPin );
dallas.requestTemperatures();
sin( 23423 );
float tempC = dallas.getTempCByIndex(0);
temperature = (double)tempC;
Time.zone(-5);
currenttime = Time.hour();
currentmin = Time.minute();
float tempF = DallasTemperature::toFahrenheit( tempC );
temperatureF = (double)tempF;
Serial.print( "Temp in C = ");
Serial.print( tempC );
Serial.print( "\t\t F = ");
Serial.println( tempF );
Serial.print( currenttime );
Serial.print( currentmin );
if( temperature <= 5 ){
digitalWrite( redPin, 0 );
digitalWrite( greenPin, 255 );
digitalWrite( bluePin, 255 );
}
if( temperature > 5 and temperature <= 20 ){
digitalWrite( redPin, 255 );
digitalWrite( greenPin, 0 );
digitalWrite( bluePin, 255 );
}
if( temperature >20 ){
digitalWrite( redPin, 255 );
digitalWrite( greenPin, 255 );
digitalWrite( bluePin, 0 );
}
if( currenttime == 7 and currentmin == 30 ){
if( (millis() - lastPhotoResistorReport) >= photoResistorCheckTime ){
lastPhotoResistorReport = millis();
if ( temperature <= 5 ) Particle.publish( "temperaturelevel", "Cold", PRIVATE );
if ( temperature > 5 and temperature <= 20 ) Particle.publish("temperaturelevel", "Cool", PRIVATE );
if ( temperature > 20 ) Particle.publish( "temperaturelevel", "Warm", PRIVATE );
};
};
if( buttonState == LOW ){
if ( temperature <= 5 ) Particle.publish( "temperaturelevel", "Cold", PRIVATE );
if ( temperature > 5 and temperature <= 20 ) Particle.publish("temperaturelevel", "Cool", PRIVATE );
if ( temperature > 20 ) Particle.publish( "temperaturelevel", "Warm", PRIVATE );
};
}
Click to Expand