So i have a very basic little program that is for a drive through.
The idea being that a member presses a button to get service if someone is not immediately there to assist them. When there is movement on a tray the magnetic contractor opens indicating that the person is being helped and that we need to stop the buzzing.
What hardware i use:
I have a LCD screen that just flashes a message when the member pushes a button.
One button (that closes) that gets pressed by the member/person wanting service.
A buzzer that only goes off at the initial button press and then every 30s for 20 buzzes regardless on how many times they press the button (to keep people sane on the inside).
I also have a magnetic contact switch (that opens) when a drawer gets pushed out to a member for service so i use this to tell the controller that the person is being served.
On both switches i have a pull down resistor. - can provide a schematic if needed
Here is my entire debug code...
WARNING
I am not a programmer, i am sure i do things very badly.
#include <LiquidCrystal.h>
//start of config variables
String line1 = "Someone will be";
String line2 = "with you shortly";
long ms_interval = 30000;
//end of config variables
bool showmessage = false;
bool timerrunning = false;
unsigned long currentmills;
bool addressed = false;
int buzzcounter =1;
bool messageblink = false;
LiquidCrystal lcd(8, 9, 7, 6, 5, 4);
void setup() {
timerrunning = false;
// put your setup code here, to run once:
analogWrite(11, 20); //LCD Contrast
lcd.begin(16, 2);
pinMode(2, INPUT); //Member Push Button
pinMode(10, OUTPUT); //Backlight Button
pinMode(12, OUTPUT); //Bell or buzzer
attachInterrupt(0, MemberPressISR, RISING); //Digital input 2
attachInterrupt(1, TrayMovementISR, FALLING); //Digital input 3
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.println("Serial Started");
}
void loop()
{
// put your main code here, to run repeatedly:
digitalWrite(10, LOW); //turns on the LCD Backlight
if (showmessage == true && timerrunning != true )// they pressed the button and they have not pressed it before
{
Serial.println("showmessage == true && timerrunning != true");
//start the countdown timer
currentmills = millis();
timerrunning = true;
//show they message on the LCD screen to acknowledge the button press
messageblink = true;
// initial BEEP
digitalWrite(12, HIGH);
delay(250);
digitalWrite(12, LOW);
}
if (timerrunning)//if the timer is running check that we are not over the delay interval
{
Serial.println("Timer Running");
if (millis() - currentmills > ms_interval && addressed != true)//if we are over the first interval period then buzz
{
Serial.println("Over the first 30s interval");
digitalWrite(12, HIGH);
delay(250);
digitalWrite(12, LOW);
currentmills = millis();
buzzcounter = buzzcounter + 1; //increment buzz counter
}
else if (currentmills > millis()) //if the counter has looped around during a press just buzz
{
Serial.println("Just Buzz - counter has looped around");
digitalWrite(12, HIGH);
delay(250);
digitalWrite(12, LOW);
currentmills = millis();
buzzcounter = buzzcounter + 1; //increment buzz counter
}
if (buzzcounter > 20) //the buzzer has been going for 20 = 10 minutes then turn off buzzer
{
Serial.println("Buzzed more than 20 times");
timerrunning = false;
buzzcounter = 0;
}
}
if (addressed == true)
{
Serial.println("Addressed = true");
delay(2000); // for debouncing on the drawer/Tray switch ?
timerrunning = false;
buzzcounter = 0;
messageblink = false;
addressed = false;
showmessage = false;
}
if (messageblink)
{
Serial.println("Blinking Message - On - Off 500ms - On");
//On period
lcd.display();
digitalWrite(10, HIGH); //turns on the LCD Backlight
lcd.setCursor(0, 0);
lcd.print(line1);
lcd.setCursor(0, 1);
lcd.print(line2);
delay(500);
//Off Period
lcd.noDisplay(); // turns off the backlight
delay(500);
lcd.display();
digitalWrite(10, HIGH); //turns on the LCD Backlight
lcd.setCursor(0, 0);
lcd.print(line1);
lcd.setCursor(0, 1);
lcd.print(line2);
lcd.noDisplay();
}
}
void MemberPressISR() {
showmessage = true;
}
void TrayMovementISR() {
addressed = true;
}
From serial monitor debugging i have received the following responses which to me does not make sense at all...
I was actually there when this happend, no one pressed the button for at least 10 min and then just randomly the buzzer started there was tray movement, but then without someone being there to push the button the buzzer started... how is showmessage being set to true without a button press?
Serial Started
Addressed = true
Addressed = true
Addressed = true
Addressed = true
Addressed = true
Addressed = true
Addressed = true
Addressed = true
Addressed = true
Addressed = true
Addressed = true
Addressed = true
Addressed = true
showmessage == true && timerrunning != true
Timer Running
Addressed = true
Addressed = true
Addressed = true
Addressed = true
Addressed = true
Addressed = true
showmessage == true && timerrunning != true
Timer Running
Addressed = true
Addressed = true
Addressed = true
Addressed = true
Addressed = true
Addressed = true
Addressed = true
Addressed = true
Addressed = true
Addressed = true
Addressed = true
Addressed = true
showmessage == true && timerrunning != true
Timer Running
Addressed = true
Addressed = true
Addressed = true
showmessage == true && timerrunning != true
Timer Running
Addressed = true
Addressed = true
Addressed = true
Addressed = true
Addressed = true
showmessage == true && timerrunning != true
Timer Running
Blinking Message - On - Off 500ms - On
Timer Running
Addressed = true
Addressed = true
Addressed = true
Addressed = true
Addressed = true
Addressed = true
showmessage == true && timerrunning != true
Timer Running
Addressed = true
Addressed = true
Addressed = true
Addressed = true
Addressed = true
showmessage == true && timerrunning != true
Timer Running
Addressed = true
Addressed = true
Addressed = true
Addressed = true
Addressed = true
showmessage == true && timerrunning != true
Timer Running
Addressed = true
Addressed = true
Addressed = true
Addressed = true
Addressed = true
Addressed = true
Addressed = true
Any help or advice would be greatly appreciated.
Thanks