I am trying to create a clock on an LCD when I upload the code below, all it displays is a very rapidly flashing 0:00 PM. Please help. This is my first time using Millis.
#include <LiquidCrystal.h> //includes LCD display library in sketch
LiquidCrystal lcd(27,26,25,24,23,22); //determines pins of the LCD display
int seconds = 0; //generates integer storing seconds
int minutes = 0; //generates integer storing and showing minutes
int hours = 12; //generates integer storing hours in 24 hour mode
int displayHours; //generates integer displaying hours in 12 hour mode
unsigned long previousMillis = 0; //creates a variable to store the amount of milliseconds since last update
const long interval = 1000; //generates integer to find 1 second interval
void setup()
{
lcd.begin(16,2); //determines size of the LCD display
}
void loop() //runs code repeatedly
{
updateSeconds(); //runs the updateSeconds function
clockShown(); //runs the clockShown function
clockConversion(); //runs the clockConversion function
}
void updateSeconds() //check to see if it's time to update the seconds integer
{
unsigned long currentMillis = millis(); //generates the number of milliseconds program has been running
if (currentMillis - previousMillis >= interval)
{
previousMillis = currentMillis; //updates the last time seconds was updated
seconds = seconds ++; //adds a second to the counter
}
}
void clockShown() //displays the time on an LCD display
{
lcd.clear(); //resets screen on LCD
lcd.setCursor(0,0); //sets the place to start writing at the top left corner of the LCD
lcd.print(displayHours); //displays hours
lcd.print(":"); //displays colon
if(minutes <= 9) //if the minute is 1 digit
{
lcd.print("0"); //displays 0
}
lcd.print(minutes); //displays minutes
if(hours < 12)lcd.print(" AM"); //displays AM in the morning
if(hours >= 12)lcd.print(" PM"); //displays PM at night
}
void clockConversion() //runs math to convert seconds minutes and hours
{
if(seconds == 60) //when seconds is 60
{
seconds = 0; //set seconds back to 0
minutes = minutes ++; //and add a minute
}
if(minutes == 60) //when minutes is 60
{
minutes = 0; //set minutes back to 0
displayHours = displayHours ++; //and add an hour
hours = hours ++; //and keep track of AM PM
}
if(displayHours == 13) //if the hour being displayed is 13
{
displayHours = 1; //make it 1 instead
}
}