Success!!
Thanks for pointing me in the right direction, I modified the code for the button inputs and it worked like a charm. To make sure that the LED's were displaying the time correctly I set the time in the top line of the code to a few different times to make sure they read correctly (taking out the code that incremented the seconds, minutes, and hours). That all worked great. so then I added back the code at the bottom to increment minutes and hours when the buttons were pressed, and the LED's went hyper again. So I changed the values from LOW to HIGH and this worked!
Here's the code that works, thanks to your help.
int second=0, minute=59, hour=23; //start the time on 00:00:00
int munit=0;
int hunit=0;
int valm=0;
int valh=0;
int ledstats=0;
int i=0;
boolean light = 1;
void setup()
{ //set outputs and inputs
pinMode(1, OUTPUT);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
pinMode(19, INPUT); // pushbutton for setting minutes
pinMode(14, INPUT); // pushbutton for setting hours
}
void loop()
{
// set up a local variable to hold the last time we moved forward one second
static unsigned long lastTick = 0;
// static variables are initialized once and keep their values between function calls
// move forward one second every 1000 milliseconds
if (millis() - lastTick >= 1000) {
lastTick = millis();
second++;
}
// move forward one minute every 60 seconds
if (second >= 60) {
minute++;
second = 0; // reset seconds to zero
}
// move forward one hour every 60 minutes
if (minute >=60) {
hour++;
minute = 0; // reset minutes to zero
}
if (hour >=24) {
hour=1;
minute = 0; // reset minutes to zero
}
munit = minute % 10; //sets the variable munit and hunit for the unit digits
hunit = hour % 10;
ledstats = digitalRead(0); // read input value, for setting leds off, but keeping count
if (ledstats == LOW) {
for(i=1;i<=13;i++){
digitalWrite(i, LOW);}
}
else {
// --- minutes ones
digitalWrite( 1, (minute%10) & 0b00000001); // 1's
digitalWrite( 2, (minute%10) & 0b00000010); // 2's
digitalWrite( 3, (minute%10) & 0b00000100); // 4's
digitalWrite( 4, (minute%10) & 0b00001000); // 8's
// --- minutes tens
digitalWrite( 5, (minute/10) & 0b00000001); // 1's
digitalWrite( 6, (minute/10) & 0b00000010); // 2's
digitalWrite( 7, (minute/10) & 0b00000100); // 4's
// --- hours ones
digitalWrite( 8, (hour%10) & 0b00000001); // 1's
digitalWrite( 9, (hour%10) & 0b00000010); // 2's
digitalWrite(10, (hour%10) & 0b00000100); // 4's
digitalWrite(11, (hour%10) & 0b00001000); // 8's
// --- hours tens
digitalWrite(12, (hour/10) & 0b00000001); // 1's
digitalWrite(13, (hour/10) & 0b00000010); // 2's
}
valm = digitalRead(19); // add one minute when pressed
if(valm== HIGH) {
minute++;
second=0;
delay(250);
}
valh = digitalRead(14); // add one hour when pressed
if(valh== HIGH) {
hour++;
second=0;
delay(250);
}
}
I also changed this section. Before it would reset hour to 0 instead of 1 after 24 hrs.
if (hour >=24) {
hour=1; // after 24 hrs reset to 1am instead of 0
minute = 0; // reset minutes to zero
}