Back to Parent

#include <time.h>
int redPin1 = A0;    // RED pin of the 1st LED bundle
int greenPin1 = D0;  // GREEN pin of the 1st LED bundle

int redPin2 = A1;    // RED pin of the 2nd LED bundle
int greenPin2 = D1;  // GREEN pin of the 2nd LED bundle

int redPin3 = A2;    // RED pin of the 3rd LED bundle
int greenPin3 = D2;  // GREEN pin of the 3rd LED bundle

int redValue = 255; // Full brightness for an Cathode RGB LED is 0, and off 255
int greenValue = 255; // Full brightness for an Cathode RGB LED is 0, and off 255
int eatout = 0; // set eatout value

long int dayChecker = Time.now() / 86400; // set to check dated
long int currentDay = Time.now() / 86400; // set to check how long it has passed

int led_park(String event) //set IFTTT connection
{
  Serial.print("event: "); //serial to track event
  Serial.println(event);

  if (event == "led") { //if IFTTT function runs, add 1 to eatout
    eatout = eatout + 1;
  }
  return eatout;
}

int programStartTime = Time.now() / 86400; // set program start time

void setup() {
  Serial.begin(9600); // for easy debugging
  Particle.function("lightUp", led_park);
  // Set all pins for output
  pinMode( redPin1, OUTPUT);
  pinMode( greenPin1, OUTPUT);

  pinMode( redPin2, OUTPUT);
  pinMode( greenPin2, OUTPUT);

  pinMode( redPin3, OUTPUT);
  pinMode( greenPin3, OUTPUT);

  startState(); // run start state function

}

void startState() {
  // set default state of all LEDs to be green
  analogWrite( redPin1, 255);
  analogWrite( greenPin1, 0);

  analogWrite( redPin2, 255);
  analogWrite( greenPin2, 0);

  analogWrite( redPin3, 255);
  analogWrite( greenPin3, 0);
}
void loop()
{
  dayChecker = Time.now() / 86400; // set day checker value using time.now

  int currentTime = Time.now(); // set current time as time.now
  eatoutblinker(); //run eatoutblinker function

  if(dayChecker > currentDay) { // check daychecker vs currentday and if its the same, reset state to default
    currentDay = dayChecker;
    eatout = 0;
    startState();
  }
  delay(900);
}

void eatoutblinker() {
//if eatout is triggered once, turn LED bundle 1 red
  if (eatout == 1) {
    analogWrite( redPin1, 0);
    analogWrite( greenPin1, greenValue);
  }

  //if eatout is triggered twice, turn LED bundle 2 red
  if (eatout == 2) {
    analogWrite( redPin2, 0);
    analogWrite( greenPin2, greenValue);
  }

  //if eatout is triggered thrice, turn LED bundle 3 red
  if (eatout == 3) {
    analogWrite( redPin3, 0);
    analogWrite( greenPin3, greenValue);
    eatout = 0;
  }

  Serial.print("eatout ");
  Serial.println(eatout);

}
Click to Expand

Content Rating

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

0