Hey guys!
I am building a reverse geocache box using an on-breadboard atmega 328 with Due on it. I ran have run into a slight issue while writing the code. For some reason, my lcd cases to work at the end of the setup function. It shows random scrolling characters for approximately 30 seconds and then displays the correct thing.
Is there a reason its hitting some kind of roadblock in communication for that time and then randomly connecting again? I originally thought it could be loose wires but that was ruled out by it always occurred as setup function ended. I wonder if it could also possibly have something to do with the arduino memory running low but that does not seem possible in this case...
Any suggestions would be greatly appreciated!
#include <LiquidCrystal.h> //include LCD library
#include <Servo.h> //Include servo library
#include <Time.h>
#include <Flash.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); //Sets up pins for LCD
const int buttonPin = 10;
Servo lockservo; // create servo object to control a servo
int LCDbtnlight = 6;
int lock = 0;
int unlock = 170;
int buttonState = 0; // variable for reading the pushbutton status
void setup() {
lcd.begin(16, 2);
lockservo.attach(13); // attaches the servo on pin 13 to the servo object
delay(7000); // Delay 7 seconds to allow time for the box to be closed.
lockservo.write(lock); // sets the servo position according to the scaled value
pinMode(LCDbtnlight, OUTPUT); //Set up the LCD Backlight and 3 green leds
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(buttonPin, INPUT); //Tactile on/off button
buttonState = digitalRead(buttonPin);
while (buttonState == LOW) {buttonState = digitalRead(buttonPin);}
resetTime();
digitalWrite(LCDbtnlight, HIGH); //turn on the lcd backlight as well as the pushbutton's backlight
lcd.clear();
FLASH_STRING_ARRAY(intro,
PSTR("Hi -------"),
PSTR(""),
PSTR("Inside of me is"),
PSTR("a gift for you!"),
PSTR("Why am I locked?"),
PSTR("Great Question!"),
PSTR("------- is pretty"),
PSTR("smart, he put a"),
PSTR("GPS inside of me"),
PSTR(""),
PSTR("For me to unlock"),
PSTR("you'll have to bring me!"),
PSTR("Where?"),
PSTR("You'll find out soon enough"),
PSTR("Let's go!>>>>>>>>>>>>>>>"));
for (int i=0; i<intro.count(); i=(i+2)) {
lcd.setCursor(0,0);
intro[i].print(lcd);
if (intro[i].length() >= 17) {
delay(2000);
for (int positionCounter = 0; positionCounter < ((intro[i].length())-16); positionCounter++) { //will make the program figure out the amount to scroll by string size
lcd.scrollDisplayLeft();
delay(200);
}
}
lcd.setCursor(0,1);
intro[i+1].print(lcd);
if (intro[i+1].length() >= 17) {
delay(2000);
for (int positionCounter = 0; positionCounter < ((intro[i+1].length())-16); positionCounter++) { //will make the program figure out the amount to scroll by string size
lcd.scrollDisplayLeft();
delay(200);
}
}
delay(3000);
lcd.clear();
}
}
void loop() {
lcd.print("5"); //this is test code to just put on the LCD. Instead of showing 555555555555555 etc,
//it shows random characters for ~30s and then it finally shows the corect 555555555555 lines.
if (minute() >= 2 && digitalRead(buttonPin) == LOW){ //Standby countdown and initiation
for (int i=0; i <= 20; i++){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Going on Standby");
lcd.setCursor(0,1);
lcd.print(20-i);
lcd.setCursor(4,1);
lcd.print("seconds");
if (digitalRead(buttonPin) == HIGH) {
resetTime();
break;
}
delay(1000);
}
lcd.clear();
digitalWrite(LCDbtnlight, LOW);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
}
}
void resetTime(){ //Resets the time in the timer
setTime(0, 0, 0, 1, 1, 2014);
}