Back to Parent

#include "OneWire.h"
#include "spark-dallas-temperature.h"

OneWire oneWire(D0);
DallasTemperature dallas(&oneWire);

double temperature = 0.0;
double temperatureF = 0.0;
int check = 0;

void setup() {
  Particle.variable("temperature", &temperature, DOUBLE);
  Particle.variable("temperatureF", &temperatureF, DOUBLE);
  pinMode(D1, OUTPUT);
  pinMode(D2, OUTPUT);
  dallas.begin();
  Serial.begin(9600);
  digitalWrite(D1,LOW);
}

void loop() {
  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;
  Serial.println(temperatureF);
if (temperatureF > 135.0){
  if (check==0)
  {
    Particle.publish("boiling-water", "high");
  }
  check = 1;
  playMario();
}
  else
{
  Particle.publish("boiling-water", "low");
  check = 0;
  digitalWrite(D1,LOW);
}
  delay(1000);
}

void playMario()
{
  digitalWrite(D2,HIGH);
  tone(D1,1320,100);
delay(150);
tone(D1,1320,100);
delay(300);
tone(D1,1320,100);
delay(300);
tone(D1,1020,100);
delay(100);
tone(D1,1320,100);
delay(300);
tone(D1,1540,100);
delay(550);
tone(D1,760,100);
delay(575);

tone(D1,1020,100);
delay(450);
tone(D1,760,100);
delay(400);
tone(D1,640,100);
delay(500);
tone(D1,880,100);
delay(300);
tone(D1,960,80);
delay(330);
tone(D1,900,100);
delay(150);
tone(D1,860,100);
delay(300);
tone(D1,760,100);
delay(200);
tone(D1,1320,80);
delay(200);
tone(D1,1520,50);
delay(150);
tone(D1,1720,100);
delay(300);
tone(D1,1400,80);
delay(150);
tone(D1,1520,50);
delay(350);
tone(D1,1320,80);
delay(300);
tone(D1,1040,80);
delay(150);
tone(D1,1160,80);
delay(150);
tone(D1,960,80);
delay(500);
digitalWrite(D2,LOW);
}
Click to Expand

Content Rating

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

0