Here is my code for a binary clock the first if statement is the problem rather than checking to see if the conditional (minute = 60) is true it just runs the code that is inside of it. I can't see any problem my self as minute is 0 and is only incremented by 1 every second.
const int pin[] = {2,3,4,5,6,7,8,9,10,11,12}; //Pins with LED's on them
int minute = 0; //Variables for keeping track
int hour = 0;
int readMin = 0; //Disposable Variables for breaking down the time into binary
int readHour = 0;
void setup() {
for (int i=0;i < 11;i++){ //used to declare all pins in pin array as an output
pinMode(pin[i], OUTPUT);
}
}
void loop() {
delay(1000);
++minute; //incrent minutes to record the time
if (minute = 60){ //if minute is equal to 60 reset it to zero and add one to hour
++hour;
minute -= 60;
}
readMin = minute; //store the time in 2 disposable variables so that the original time is stored
readHour = hour;
//Hours
//breaks down the number to binary by seeing if it is big enough for 16 to be subtracted from it
if (readHour >= 16){
digitalWrite(pin[0], HIGH); //turns light on if true and off if false
readHour -= 16;
}else{
digitalWrite(pin[0], LOW);
}
//breaks down the number to binary by seeing if it is big enough for 8 to be subtracted from it
if (readHour >= 8){
digitalWrite(pin[1], HIGH); //turns LED on if true and off if false
readHour -= 8;
}else{
digitalWrite(pin[1], LOW);
}
//breaks down the number to binary by seeing if it is big enough for 4 to be subtracted from it
if (readHour >= 4){
digitalWrite(pin[2], HIGH); //turns LED on if true and off if false
readHour -= 4;
}else{
digitalWrite(pin[2], LOW);
}
//breaks down the number to binary by seeing if it is big enough for 2 to be subtracted from it
if (readHour >= 2){
digitalWrite(pin[3], HIGH); //turns LED on if true and off if false
readHour -= 2;
}else{
digitalWrite(pin[3], LOW);
}
//breaks down the number to binary by seeing if it is big enough for 1 to be subtracted from it
if (readHour >= 1){
digitalWrite(pin[4], HIGH); //turns LED on if true and off if false
readHour -= 1;
}else{
digitalWrite(pin[4], LOW);
}
//minutes
//breaks down the number to binary by seeing if it is big enough for 32 to be subtracted from it
if (readMin >= 32){
digitalWrite(pin[5], HIGH); //turns LED on if true and off if false
readMin -= 32;
}else{
digitalWrite(pin[5], LOW);
}
//breaks down the number to binary by seeing if it is big enough for 16 to be subtracted from it
if (readMin >= 16){
digitalWrite(pin[6], HIGH); //turns LED on if true and off if false
readMin -= 16;
}else{
digitalWrite(pin[6], LOW);
}
//breaks down the number to binary by seeing if it is big enough for 8 to be subtracted from it
if (readMin >= 8){
digitalWrite(pin[7], HIGH); //turns LED on if true and off if false
readMin -= 8;
}else{
digitalWrite(pin[7], LOW);
}
//breaks down the number to binary by seeing if it is big enough for 4 to be subtracted from it
if (readMin >= 4){
digitalWrite(pin[8], HIGH); //turns LED on if true and off if false
readMin -= 4;
}else{
digitalWrite(pin[8], LOW);
}
//breaks down the number to binary by seeing if it is big enough for 2 to be subtracted from it
if (readMin >= 2){
digitalWrite(pin[9], HIGH); //turns LED on if true and off if false
readMin -= 2;
}else{
digitalWrite(pin[9], LOW);
}
//breaks down the number to binary by seeing if it is big enough for 1 to be subtracted from it
if (readMin >= 1){
digitalWrite(pin[10], HIGH); //turns LED on if true and off if false
readMin -= 32;
}else{
digitalWrite(pin[10], LOW);
}
}