Back to Parent

Code

#include "OneWire.h"

#include "spark-dallas-temperature.h"

OneWire oneWire(A0);

DallasTemperature dallas(&oneWire);

double temperature = 0.0;

double temperatureF = 0.0;

#include <math.h>

int ledPin = D1;

int ledValue = 0;

int speakerPin = D2;

int melody[] = {3830, 3830, 4000, 3830, 5000,};

int noteDurations[] = {6,6,6,4,4};

void setup()

{

Particle.variable("temperature", &temperature, DOUBLE);

Particle.variable("temperatureF", &temperatureF, DOUBLE);

dallas.begin();

Serial.begin(9600);

pinMode (ledPin, OUTPUT);

pinMode( speakerPin, OUTPUT );

playNotes();

}

void loop()

{

if ( getTemp() > 25)

{

playNotes();

blinkLed();

delay( 6000 );

}

if ( getTemp() > 20)

{

Particle.publish("oventxt","You left the oven on");

}

}

int getTemp ()

{

dallas.requestTemperatures();

sin( 23423 );

float tempC = dallas.getTempCByIndex(0);

temperature = (double)tempC;

float tempF = DallasTemperature::toFahrenheit( tempC );

temperatureF = (double)tempF;

Serial.print( "Temp in C = ");

Serial.print( tempC );

Serial.print( "\t\t F = ");

Serial.println( tempF );

return tempC;

}

void playNotes()

{

for (int thisNote = 0; thisNote < 8; thisNote++) {

int noteDuration = 1000/noteDurations[thisNote];

tone(speakerPin, melody[thisNote],noteDuration);

int pauseBetweenNotes = noteDuration * 1.30;

delay(pauseBetweenNotes);

noTone(speakerPin);

}

}

void blinkLed()

{

digitalWrite ( ledPin , HIGH );

delay ( 500 );

digitalWrite (ledPin, LOW );

delay( 500 );

digitalWrite ( ledPin , HIGH );

delay ( 500 );

digitalWrite (ledPin, LOW );

delay( 500 );

digitalWrite ( ledPin , HIGH );

delay ( 500 );

digitalWrite (ledPin, LOW );

delay( 500 );

digitalWrite ( ledPin , HIGH );

delay ( 500 );

digitalWrite (ledPin, LOW );

delay( 500 );

digitalWrite ( ledPin , HIGH );

delay ( 500 );

digitalWrite (ledPin, LOW );

delay( 3000 );

}


Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!

0