That makes perfect sense. It has been a very long time since I've coded in c++ but some of this is coming back. Do you think the way I have it now is acceptable?
Alright well I have a working clock. In my excitement to get it all working I may have mangled my code a bit. I had to add a crude setup process so you could set the right time. Still it is wonderful that I got it up and running.
Now I can refine it and improve it. Since this is the first real thing I've made with Arduino it has spiked a load of questions regarding electronics. Some of resistors I used were guess work. I'll probably post some followup questions in the electronics forum.
Below is what I have so far in my code.
//#define NUM_ITEMS(arg) ((unsigned int) (sizeof (arg) / sizeof (arg [0])))
int const MINUTES[] = {13, 12, 11, 10, 9, 8};
int const HOURS[] = {7, 6, 5, 4};
int hours = 1;
int minute = 0;
int setup_time = 10000;
void setup() {
for(int led = 4; led < 14; led++){
pinMode(led, OUTPUT);
}
//Serial.begin(9600);
pinMode(3, INPUT);
}
//int array_size(int const a[]) {
// return (sizeof(a)/sizeof(int));
//}
void blink_binary_number(int number, int const pin_array[], int a_size){
for(int led = 0; led < a_size; led++){
if (bitRead(number, led) == 1){
digitalWrite(pin_array[led], HIGH);
} else {
digitalWrite(pin_array[led], LOW);
}
}
}
void loop() {
while (setup_time > 0) {
if (digitalRead(3) == HIGH) {
// Serial.print("Minute: ");
// Serial.println(minute);
// Serial.print("Hour: ");
// Serial.println(hours);
// Serial.println("------");
blink_binary_number(hours, HOURS, 4);
blink_binary_number(minute, MINUTES, 6);
//Incriment time
minute++;
if (minute == 60) {
minute = 0;
hours++;
}
if (hours > 12) {
hours = 1;
}
delay(150);
setup_time = 10000;
} else {
delay(10);
setup_time = setup_time - 10;
}
}
// Serial.print("Minute: ");
// Serial.println(minute);
// Serial.print("Hour: ");
// Serial.println(hours);
// Serial.println("------");
blink_binary_number(hours, HOURS, 4);
blink_binary_number(minute, MINUTES, 6);
//Incriment time
minute++;
if (minute == 60) {
minute = 0;
hours++;
}
if (hours > 12) {
hours = 1;
}
delay(60000);
}
Uploading a video now.
Video of the clock.