Back to Parent

// Identify initial variables
int greenLED = D0;
int redLED = D1;
int coffeeCount = 0;

void setup()
{
  // Set pins to outlet and turn both off
  pinMode(redLED, OUTPUT);
  pinMode(greenLED, OUTPUT);
  digitalWrite(greenLED, LOW);
  digitalWrite(redLED, LOW);

  // Create the handleNewCoffeeSpend function
  Particle.function( "coffeeSpend", handleNewCoffeeSpend );
  Serial.begin( 9600 );
}

// Call the function when triggered by IFTTT
int handleNewCoffeeSpend( String command )
{
    // Print message in serial monitor that says a command was received
    Serial.println( "Received = " );
    Serial.println( command );

    // Increase the coffeeCount by 1 when a trigger is received from IFTTT
    coffeeCount = coffeeCount+1;

    // Check the coffeeCount in the serial monitor
    Serial.print( "coffeeCount = ");
    Serial.println( coffeeCount );


    if (coffeeCount < 2)
    {
      // coffeeCount is < 2, Turn on green LED and enjoy starbucks!
      digitalWrite(greenLED, HIGH);
      digitalWrite(redLED, LOW);
      return 1;
    }

    else
    {
      // If coffee count is >= 2, turn red LED on and make coffee at home
      digitalWrite(redLED, HIGH);
      digitalWrite(greenLED, LOW);
      return 0;
    }
}

void loop()
{
// Reset the coffeCount to 0 at the beginning of the week.
  if (Time.weekday()==1)
  {
    coffeeCount=0;
  }
}
Click to Expand

Content Rating

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

0