I have tried everything but I can't get my binary clock to display correctly. The diagram and code are here: Binary Clock | Electronics Lab.
The hardware is based off this (it also explains the process that my program is trying to do): DIY: Binary Clock with Arduino. The problems lie in a, probably, simple error as my variable tempTime
, which is used to convert the individual digits to their binary equivalent, does not change when I tell it to. All this occurs in the display function. (Sorry, I'm new Here and only a high school student)
While debugging it I realized that the only problem is the variable tempTime
- the hardware and other functions work as they were intended.
Can anyone help? (Sorry if this is not very well documented).
int digitPins[4][4] = {{13,6,-1,-1},{12,7,3,1},{11,8,4,-1},{10,9,5,2}};
int time[4] = {0,0,0,0};
int steps[4]={1,2,4,8};
int tempTime = 0;
void setup(){
for(int x = 0; x < 4; x++){
for(int y =0; y<4; y++){
pinMode(digitPins[x][y],OUTPUT);
}
}
Serial.begin(9600);
convertHour(12);
convertMinute(57);
Serial.println("The time is:");
for(int z = 0; z < 4; z++){
if(z == 2){
Serial.print(":");
}
Serial.print(time[z]);
}
display();
}
void loop(){
}
void display(){
int displayer[13] = {0,0,0,0,0,0,0,0,0,0,0,0,0};
/*
0 - Hour
1 - Hour
2 - Minute
3 - Minute
4 - Hour(Total)
5 - Minute(Total)
*/
int counter1 = 0;
for(int i = 0; i < 4; i++){ //Loop for the individual digits
tempTime = time[i];
if(tempTime >= 10){
tempTime = tempTime % 10;
}
Serial.print("\nBegining new iteration i = ");
Serial.print("\nStarting with digit: ");
Serial.print(tempTime);
Serial.print(i);
Serial.println("");
for(int j = 3; j >= 0; j--){//Loop to determin the arrangement
if(time[i]/steps[j] >= 1 && steps[j] > 0 && digitPins[i][j] > 0){
Serial.print("\n");
Serial.print(time[i]);
Serial.print("/");
Serial.print(steps[j]);
Serial.print(" = ");
Serial.print(time[i]/steps[j]);
tempTime =tempTime - (time[i]*steps[j]);
displayer[counter1] = digitPins[i][j];
Serial.print("\nAdded: ");
Serial.print(digitPins[i][j]);
counter1++;
}
}
}
clear();
for(int a = 0; a < 13; a++){
digitalWrite(displayer[a],HIGH);
}
}
void clear(){
for(int x = 0; x < 4; x++){
for(int y =0; y<4; y++){
digitalWrite(digitPins[x][y],LOW);
}
}
}
void convertHour(int value){
int digits[] = {0,0};
if(value >= 10){
debug("Bigger than 10");
if(value >= 20){
digits[0] = 2;
}else{
digits[0] = 1;
}
}
digits[1] = value - (digits[0] * 10);
//String hour = digits[0]+""+digits[1];
//Serial.print(digits[0]);
//Serial.print(digits[1]);
time[0] = digits[0];
time[1] = digits[1];
}
void convertMinute(int value){
int digits[2] = {0,0};
int val = value;
if(value >= 10){
digits[0] = val/10;
}
digits[1] = value - (digits[0] * 10);
Serial.print("\n");
Serial.print(digits[0]);
Serial.print(digits[1]);
time[2] = digits[0];
time[3] = digits[1];
}
void debug(String value){
boolean de = true;
if(de){
Serial.println(value);
}
}
Ctrl+K
to have your browser do this for you. If that link goes down the question, and any following answer, will be meaningless.