Back to Parent

// 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"

// -----------------
// 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;
double fakeTemp = 0.0;
#include <math.h>

int LedPin1 = D2;
int LedPin2 = D3;
int LedPin3 = D4;

int Button1 = D5;
int Button2 = D6;
int Button3 = D7;
int state = 0;

int button1State = HIGH;
int button2State = HIGH;
int button3State = HIGH;

long frameCount = 0;

void setup()
{
  // Register a Particle Core variable here
  Particle.variable("temperature", &temperature, DOUBLE);
  Particle.variable("temperatureF", &temperatureF, DOUBLE);
  Particle.variable("state", state);

  Particle.function("setTemp", setTemp);

  pinMode(LedPin1, OUTPUT);
  pinMode(LedPin2, OUTPUT);
  pinMode(LedPin3, OUTPUT);
  pinMode(Button1, INPUT_PULLUP);
  pinMode(Button2, INPUT_PULLUP);
  pinMode(Button3, INPUT_PULLUP);

  // setup the library
  dallas.begin();

  Serial.begin(9600);

}


void loop()
{
  frameCount++;

  if(frameCount%3000 == 0)  {
    // Request temperature conversion (traditional)
    dallas.requestTemperatures();

    sin( 23423 );

    // 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;

    //USE FOR TESTING
    temperatureF = fakeTemp;

    /*// Print out
    Serial.print( "Temp in C = ");
    Serial.print( tempC );
    Serial.print( "\t\t F = ");
    Serial.println( tempF );*/
  }

  button1State = digitalRead(Button1);
  button2State = digitalRead(Button2);
  button3State = digitalRead(Button3);

  if(button1State == LOW) {
    state = 1;
  }
  if(button2State == LOW) {
    state = 2;
  }
  if(button3State == LOW) {
    state = 3;
  }

  /*Serial.println(state);*/


//White/Green Tea
if (state ==1 ) {
  turnLedOff();
  if (temperatureF >= 170 && temperatureF <= 185) {
    digitalWrite(LedPin1, HIGH);
    digitalWrite(LedPin2, LOW);
    digitalWrite(LedPin3, LOW);
  }
 else {
   digitalWrite(LedPin1, LOW);
 }
}

//Olong
if (state ==2){
  turnLedOff();
  if(temperatureF >= 180 && temperatureF <= 190){
    digitalWrite(LedPin2, HIGH);}

    else{
      digitalWrite(LedPin2, LOW);}}

//Black/Herbal
if (state ==3){
   turnLedOff();
   if(temperatureF >= 208 && temperatureF <= 212){
     digitalWrite(LedPin3, HIGH);
     digitalWrite(LedPin2, LOW);
     digitalWrite(LedPin1, LOW);}
    else{
      digitalWrite(LedPin3, LOW);}}

/*delay(5000);*/
}

void turnLedOff(){
  digitalWrite(LedPin3, LOW);
  digitalWrite(LedPin2, LOW);
  digitalWrite(LedPin1, LOW);

}

int setTemp(String input) {

  fakeTemp = atoi(input);
  return 0;
}

/*
The API request will look something like this:
GET /v1/devices/{DEVICE_ID}/temperature

# EXAMPLE REQUEST IN TERMINAL
# Core ID is 0123456789abcdef
# Your access token is 123412341234
curl -G https://api.particle.io/v1/devices/0123456789abcdef/temperature \
  -d access_token=123412341234
*/
Click to Expand

Content Rating

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

-1