Hi, I'm new to Arduino and I'm doing a high school project on it. I did this project: Arduino Lock Box | Arduino Project Hub and it seems to be working fine, the only thing is that the timer isn't showing up on the LCD screen; I might have used the wrong library for time, the project description didn't really say which one to use. Or, I just don't understand how to work it. Also, I wanted to add LED lights or something else after it gets unlocked but there isn't enough space on the board. Is there a way to combine 2 boards in a sketch? I'm using Arduino IDE 2.3.5 to code. Thanks!
Update-
Here is my code and pictures of my board:
#include <Time.h>
#include <TimeLib.h>
#include <LiquidCrystal.h>
#include <EEPROM.h>
#include <Servo.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
Servo myServo;
const int BackButtonPin = 6;
const int StartButtonPin = 7;
const int MinusButtonPin = 8;
const int PlusButtonPin = 9;
int settingHours = 0;
int settingMinutes = 0;
int settingSeconds = 0;
time_t settingTime = 0;
int activeHours = 0;
int activeMinutes = 0;
int activeSeconds = 0;
time_t activeTime = 0;
time_t startTime = 0;
time_t elapsedTime = 0;
int BackButtonState = LOW;
long BackButtonLongPressTime = 0;
int StartButtonState = LOW;
int PlusButtonState = LOW;
int MinusButtonState = LOW;
int BackButtonPrevState = LOW;
int StartButtonPrevState = LOW;
int PlusButtonPrevState = LOW;
int MinusButtonPrevState = LOW;
bool BackButtonPress = false;
bool BackButtonLongPress = false;
bool StartButtonPress = false;
bool PlusButtonPress = false;
bool MinusButtonPress = false;
bool locked = false;
const int READY = 0;
const int SETTINGS = 1;
const int LOCKED = 2;
const int UNLOCKED = 3;
int activeState = READY;
int timeData = 0;
void setup() {
lcd.begin(16, 2);
pinMode(BackButtonPin, INPUT);
pinMode(StartButtonPin, INPUT);
pinMode(PlusButtonPin, INPUT);
pinMode(MinusButtonPin, INPUT);
myServo.attach(10);
Serial.begin(9600);
myServo.write(90);
}
void loop() {
StartButtonPress = false;
PlusButtonPress = false;
MinusButtonPress = false;
BackButtonPress = false;
BackButtonLongPress = false;
BackButtonState = digitalRead(BackButtonPin);
if (BackButtonState != BackButtonPrevState) {
BackButtonPress = BackButtonState == HIGH;
BackButtonPrevState = BackButtonState;
} else {
if (BackButtonState == HIGH) {
BackButtonLongPressTime++;
if (BackButtonLongPressTime == 100) {
BackButtonPress = false;
BackButtonLongPress = true;
BackButtonLongPressTime = 0;
}
} else {
BackButtonLongPressTime = 0;
BackButtonPress = false;
BackButtonLongPress = false;
}
}
StartButtonPress = false;
StartButtonState = digitalRead(StartButtonPin);
if (StartButtonState != StartButtonPrevState) {
StartButtonPress = StartButtonState == HIGH;
StartButtonPrevState = StartButtonState;
}
MinusButtonPress = false;
MinusButtonState = digitalRead(MinusButtonPin);
if (MinusButtonState != MinusButtonPrevState) {
MinusButtonPress = MinusButtonState == HIGH;
MinusButtonPrevState = MinusButtonState;
}
PlusButtonPress = false;
PlusButtonState = digitalRead(PlusButtonPin);
if (PlusButtonState != PlusButtonPrevState) {
PlusButtonPress = PlusButtonState == HIGH;
PlusButtonPrevState = PlusButtonState;
}
switch (activeState) {
case READY:
myServo.write(90);
if (BackButtonPress) {
Reset();
}
if (BackButtonPress) {
activeState = SETTINGS;
}
if (StartButtonPress) {
activeState = activeState == READY ? LOCKED : READY;
if (activeState == LOCKED) {
startTime = now();
}
}
break;
case SETTINGS:
myServo.write(90);
if (BackButtonPress) {
settingTime = settingSeconds + (60 * settingMinutes) + (3600 * settingHours);
activeHours = settingHours;
activeMinutes = settingMinutes;
activeSeconds = settingSeconds;
timeData = 0;
activeState = READY;
}
if (StartButtonPress) {
timeData++;
if (timeData == 3) {
timeData = 0;
}
}
if (MinusButtonPress) {
switch (timeData) {
case 0:
settingHours--;
if (settingHours == -1) {
settingHours = 99;
}
break;
case 1:
settingMinutes--;
if (settingMinutes == -1) {
settingMinutes = 59;
}
break;
case 2:
settingSeconds--;
if (settingSeconds == -1) {
settingSeconds = 59;
}
break;
}
}
if (PlusButtonPress) {
switch (timeData) {
case 0:
settingHours++;
if (settingHours == 100) {
settingHours = 0;
}
break;
case 1:
settingMinutes++;
if (settingMinutes == 60) {
settingMinutes = 0;
}
break;
case 2:
settingSeconds++;
if (settingSeconds == 60) {
settingSeconds = 0;
}
break;
}
}
break;
case LOCKED:
myServo.write(0);
if (StartButtonPress) {
activeState = READY;
}
if (BackButtonPress) {
Reset();
activeState = READY;
}
break;
case UNLOCKED:
myServo.write(90);
if (BackButtonPress || StartButtonPress || MinusButtonPress || PlusButtonPress) {
activeState = READY;
}
break;
}
switch (activeState) {
case READY:
case SETTINGS:
break;
case LOCKED:
activeTime = settingTime - (now() - startTime);
if (activeTime <= 0) {
activeState = UNLOCKED;
}
break;
}
lcd.setCursor(0, 0);
switch (activeState) {
case READY:
lcd.print("READY: Start ");
lcd.setCursor(0, 1);
lcd.print(activeHours);
lcd.print(" ");
lcd.print(activeMinutes);
lcd.print(" ");
lcd.print(activeSeconds);
lcd.print(" ");
break;
case SETTINGS:
lcd.print("Set Timer: ");
switch (timeData) {
case 0:
lcd.print("HRS ");
break;
case 1:
lcd.print("MINS");
break;
case 2:
lcd.print("SECS");
break;
}
lcd.setCursor(0, 1);
lcd.print(settingHours);
lcd.print(" ");
lcd.print(settingMinutes);
lcd.print(" ");
lcd.print(settingSeconds);
lcd.print(" ");
break;
case LOCKED:
lcd.print("Waiting... ");
lcd.setCursor(0, 1);
if (hour(activeTime) < 10) lcd.print("0");
lcd.print(hour(activeTime));
lcd.print(": ");
if (minute(activeTime) < 10) lcd.print("0");
lcd.print(minute(activeTime));
lcd.print(": ");
if (second(activeTime) < 10) lcd.print("0");
lcd.print(second(activeTime));
break;
case UNLOCKED:
lcd.print(" UNCLOCKED! ");
lcd.setCursor(0, 1);
lcd.print(" ");
break;
}
delay(10);
}
void Reset() {
activeState = READY;
activeHours = settingHours;
activeMinutes = settingMinutes;
activeSeconds = settingSeconds;
}
I took this picture without the LCD as I was building it, I don't have one with it, but this link: LCD White Boxes has pictures with the LCD. In my opinion I think that it would be too difficult for me to include LEDs on this board because of the wires so that's why I want to add another board, I just don't know how.
