Back to Parent

/*
v1.3
This is the third iteration of the DIGITAL DINNER BELL.
The basic concept was developed by me during my undergraduate years.
This is my first IoT device aduino based device.

It was created as part of an IoT CMU class.
This version is really basic and uses a button for the input.

Jacob Kirk Maxfield
Jan 29, 2016  -- v1.2
Jan 30, 2016 -- v1.3

Special thanks to Stephen N., Daragh B., the
Programming Electronics Academy YouTube channel
and others that helped me along the way.

*/

int ledPin = D3;    //LED to show contact with button; I used a RED LED
int buttonPin = D2; //Button to represent strikes of bell
int sentLed = A5;   //Indicate that 3 strikes have occurred; I used a GREEN LED

int count = 0;
int buttonState = 0;
int timer = 0;
int resetTime = 3000;

/* SETUP
-----------------------------------------------*/

void setup ()
{
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
pinMode(sentLed, OUTPUT);

Serial.begin(9600); //to check the count on the serial monitor
}

/* LOOP
-----------------------------------------------*/

void loop ()
{
buttonState = digitalRead(buttonPin);

  if (buttonState == HIGH) //count the strikes
  {
    digitalWrite(ledPin, HIGH); //this light indicates that a proper sense has happened
    count++;
    Serial.println(count); //watch the count on the serial monitor
    delay(100);
    if (count == 1 || count == 2 || count == 3) //set the timer so I can time out the button set
    {
      timer = millis();
    }
  }
  digitalWrite(ledPin, LOW);
  delay(100); //this delay is just to prevent quick succession counts, may need to be adjusted

  if (count > 2) //if the strikes reach 3 then send the message
  {
    Particle.publish ("dinnerBell"); //Publishes the event
    digitalWrite(sentLed, HIGH);
    delay(1000);
    digitalWrite(sentLed, LOW);
    count = 0;
  }

  if (millis() - resetTime > timer) //reset the count if too much time has past
  {
    count = 0;
  }

}

/* VARIABLES
-----------------------------------------------*/
//nothing here
Click to Expand

Content Rating

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

0