If else statement for clock bugging out.

Hi
I’m trying to make a program to control a nixie clock, with outputs going to 74141 decoders. The program currently relies on a massive if else statement, run once each minute, to figure out which tube needs to be displaying which value. Unfortunately, this statement doesn’t seem to be working as when launched it jumps straight to 11:11, then stays there, and keeps sending out the same values.

Code: http://pastebin.com/cTpFWfn8

Any help?

#include <Event.h>
#include <Timer.h>

Timer t;

// multiplier for time delay, to adjust
int timeModifierNumerator = 1;
int timeModifierDenominator = 1;
// how often to count each minute
int clockTick = 1000*timeModifierNumerator*60/timeModifierDenominator;
// 24 or 12 hour time
int timeType = 12;
int started = 0;

// number for each tube + starting value for time setting
int tubeA = 0;
int tubeB = 0;
int tubeC = 0;
int tubeD = 0;

//pin names!
// tens of hours, 0-2
int oneA = 13;
int twoA = 12;
// units of hours, 0-9
int oneB = 11;
int twoB = 10;
int fourB = 9;
int eightB = 8;
//tens of minutes, 0-6
int oneC = 7;
int twoC = 6;
int fourC = 5;
//units of minutes, 0-9
int oneD = 4;
int twoD = 3;
int fourD = 2;
int eightD = 1;


// setup, output all the things!
void setup(){
 Serial.begin(9600);
 Serial.print("Feed_Started");
 Serial.print('\n');
  pinMode(oneA, OUTPUT);
  pinMode(twoA, OUTPUT);
  pinMode(oneB, OUTPUT);
  pinMode(twoB, OUTPUT);
  pinMode(fourB, OUTPUT);
  pinMode(eightB, OUTPUT);
  pinMode(oneC, OUTPUT);
  pinMode(twoC, OUTPUT);
  pinMode(fourC, OUTPUT);
  pinMode(oneD, OUTPUT);
  pinMode(twoD, OUTPUT);
  pinMode(fourD, OUTPUT);
  pinMode(eightD, OUTPUT);
  
// call count according to timer
t.every(clockTick, count);
  
}

void loop (){
//update timer
t.update();

}

// public loop for generating time
void count(){
Serial.print("minute Counted");
Serial.print('\n');
  // increment minutes
  if (tubeD < 9) {
    tubeD = tubeD+1;
  }
  // increment tens of minutes
  else if (tubeD = 9, tubeC < 5){
    tubeD = 0;
    tubeC = tubeC+1;
  }
  // increment hours
  
  // increment hours for first 9 hours
  else if (tubeD = 9, tubeC = 5, tubeB < 9, tubeA = 0){
    tubeD = 0;
    tubeC = 0;
    tubeB = tubeB +1;
  }
  // increment hours for 12 hour time from 10-12
  else if (tubeD =9, tubeC = 5, tubeA = 1, timeType = 12, tubeB < 2){
    tubeD = 0;
    tubeC = 0;
    tubeB = tubeB + 1;
  }
  // increment hours 10-19 if 24 hour time
  else if (tubeD =9, tubeC = 5, tubeA = 1, timeType = 24, tubeB < 9){
    tubeD = 0;
    tubeC = 0;
    tubeB = tubeB + 1;
  }
  // increment hours 20-24
  else if (tubeD =9, tubeC = 5, tubeA = 2, timeType = 24, tubeB < 4){
    tubeD = 0;
    tubeC = 0;
    tubeB = tubeB + 1;
  }
  
  // increment tens of hours from 0
  else if (tubeD = 9, tubeC = 5, tubeB = 9, tubeA =0) {
    tubeD = 0;
    tubeC = 0;
    tubeB = 0;
    tubeA = 1;
  }
  // reset clock to 01:00 if twelve hour time
  else if (tubeD = 9, tubeC = 5, tubeB = 2, tubeA =1, timeType = 12) {
    tubeD = 0;
    tubeC = 0;
    tubeB = 1;
    tubeA = 0;
  }
  // increment tens of hours if twenty-four hour time
  else if (tubeD = 9, tubeC = 5, tubeB = 9, tubeA = 1, timeType = 24) {
    tubeD = 0;
    tubeC = 0;
    tubeB = 0;
    tubeA = 2;
  }
  // reset clock to 01:00 if twenty-four hour time
  else if (tubeD = 9, tubeC = 5, tubeB = 4, tubeA = 2) {
    tubeD = 1;
    tubeC = 0;
    tubeB = 0;
    tubeA = 0;
  }
  // cry moment
  else {
  Serial.print("something is broken");
  }
  
  //update time on tubes
  displayA();
  displayB();
  displayC();
  displayD();
  // print current time on tubes for debugging
  Serial.print('\n');
  Serial.print(tubeA);
  Serial.print(tubeB);
  Serial.print(tubeC);
  Serial.print(tubeD);
  Serial.print('\n');
}
// outputs to driver for tube A
void displayA() {
 
  
	if (tubeA = 0) {
	 Serial.print("A0");
  digitalWrite(oneA, LOW);
  digitalWrite(twoA, LOW);
}
else if (tubeA = 1) {
 Serial.print("A1");
  digitalWrite(oneA, HIGH);
  digitalWrite(twoA, LOW);
}
else if (tubeA = 2) {
 Serial.print("A2");
  digitalWrite(oneA, LOW);
  digitalWrite(twoA, HIGH);
}

}

// outputs to driver for tube B
void displayB() {
  

  if (tubeB = 0) {
   Serial.print("B0");
  digitalWrite(oneB, LOW);
  digitalWrite(twoB, LOW);
  digitalWrite(fourB, LOW);
  digitalWrite(eightB, LOW);
}
 else if (tubeB = 1) {
  Serial.print("B1");
  digitalWrite(oneB, HIGH);
  digitalWrite(twoB, LOW);
  digitalWrite(fourB, LOW);
  digitalWrite(eightB, LOW);
}
 else if (tubeB = 2) {
  Serial.print("B2");
  digitalWrite(oneB, LOW);
  digitalWrite(twoB, HIGH);
  digitalWrite(fourB, LOW);
  digitalWrite(eightB, LOW);
}
 else if (tubeB = 3) {
  Serial.print("B3");
  digitalWrite(oneB, HIGH);
  digitalWrite(twoB, HIGH);
  digitalWrite(fourB, LOW);
  digitalWrite(eightB, LOW);
}
 else if (tubeB = 4) {
  Serial.print("B4");
  digitalWrite(oneB, LOW);
  digitalWrite(twoB, LOW);
  digitalWrite(fourB, HIGH);
  digitalWrite(eightB, LOW);
}
 else if (tubeB = 5) {
  Serial.print("B5");
  digitalWrite(oneB, HIGH);
  digitalWrite(twoB, LOW);
  digitalWrite(fourB, HIGH);
  digitalWrite(eightB, LOW);
}
 else if (tubeB = 6) {
  Serial.print("B6");
  digitalWrite(oneB, LOW);
  digitalWrite(twoB, HIGH);
  digitalWrite(fourB, HIGH);
  digitalWrite(eightB, LOW);
}
 else if (tubeB = 7) {
  Serial.print("B7");
  digitalWrite(oneB, HIGH);
  digitalWrite(twoB, HIGH);
  digitalWrite(fourB, HIGH);
  digitalWrite(eightB, LOW);
}
 else if (tubeB = 8) {
  Serial.print("B8");
  digitalWrite(oneB, LOW);
  digitalWrite(twoB, LOW);
  digitalWrite(fourB, LOW);
  digitalWrite(eightB, HIGH);
}
 else if(tubeB = 9) {
  Serial.print("B9");
  digitalWrite(oneB, HIGH);
  digitalWrite(twoB, LOW);
  digitalWrite(fourB, LOW);
  digitalWrite(eightB, HIGH);
}

}

// output to C
void displayC(){
   if (tubeC = 0) {
    Serial.print("C0");
  digitalWrite(oneC, LOW);
  digitalWrite(twoC, LOW);
  digitalWrite(fourC, LOW);
}
  else if (tubeC = 1) {
   Serial.print("C1");
  digitalWrite(oneC, HIGH);
  digitalWrite(twoC, LOW);
  digitalWrite(fourC, LOW);
}
  else if (tubeC = 2) {
   Serial.print("C2");
  digitalWrite(oneC, LOW);
  digitalWrite(twoC, HIGH);
  digitalWrite(fourC, LOW);
}
  else if (tubeC = 3) {
   Serial.print("C3");
  digitalWrite(oneC, HIGH);
  digitalWrite(twoC, HIGH);
  digitalWrite(fourC, LOW);
}
  else if (tubeC = 4) {
   Serial.print("C4");
  digitalWrite(oneC, LOW);
  digitalWrite(twoC, LOW);
  digitalWrite(fourC, HIGH);
}
  else if (tubeC = 5) {
   Serial.print("C5");
  digitalWrite(oneC, HIGH);
  digitalWrite(twoC, LOW);
  digitalWrite(fourC, HIGH);
}
 
}
// output to D
 void displayD() {
  if (tubeD = 0) {
   Serial.print("D0");
  digitalWrite(oneD, LOW);
  digitalWrite(twoD, LOW);
  digitalWrite(fourD, LOW);
  digitalWrite(eightD, LOW);
}
 else if (tubeD = 1) {
  Serial.print("D1");
  digitalWrite(oneD, HIGH);
  digitalWrite(twoD, LOW);
  digitalWrite(fourD, LOW);
  digitalWrite(eightD, LOW);
}
 else if (tubeD = 2) {
  Serial.print("D2");
  digitalWrite(oneD, LOW);
  digitalWrite(twoD, HIGH);
  digitalWrite(fourD, LOW);
  digitalWrite(eightD, LOW);
}
 else if (tubeD = 3) {
  Serial.print("D3");
  digitalWrite(oneD, HIGH);
  digitalWrite(twoD, HIGH);
  digitalWrite(fourD, LOW);
  digitalWrite(eightD, LOW);
}
 else if (tubeD = 4) {
  Serial.print("D4");
  digitalWrite(oneD, LOW);
  digitalWrite(twoD, LOW);
  digitalWrite(fourD, HIGH);
  digitalWrite(eightD, LOW);
}
 else if (tubeD = 5) {
  Serial.print("D5");
  digitalWrite(oneD, HIGH);
  digitalWrite(twoD, LOW);
  digitalWrite(fourD, HIGH);
  digitalWrite(eightD, LOW);
}
 else if (tubeD = 6) {
  Serial.print("D6");
  digitalWrite(oneD, LOW);
  digitalWrite(twoD, HIGH);
  digitalWrite(fourD, HIGH);
  digitalWrite(eightD, LOW);
}
 else if (tubeD = 7) {
  Serial.print("D7");
  digitalWrite(oneD, HIGH);
  digitalWrite(twoD, HIGH);
  digitalWrite(fourD, HIGH);
  digitalWrite(eightD, LOW);
}
 else if (tubeD = 8) {
  Serial.print("D8");
  digitalWrite(oneD, LOW);
  digitalWrite(twoD, LOW);
  digitalWrite(fourD, LOW);
  digitalWrite(eightD, HIGH);
}
 else if (tubeD = 9) {
 Serial.print("D9");
  digitalWrite(oneD, HIGH);
  digitalWrite(twoD, LOW);
  digitalWrite(fourD, LOW);
  digitalWrite(eightD, HIGH);
}
}

If you post your code here it will be easier to help, especially since your link does not work. And please use code brackets for code and url brackets for links in order to help people to help you

If the code is large you can attach it to your message.

The usual problem.

void displayC(){
       if (tubeC = 0) {

else if (tubeD = 9, tubeC = 5, tubeB = 4, tubeA = 2) {

Also, do you want these to be ORs / ANDs

else if (tubeD == 9 || tubeC == 5 || tubeB == 4 || tubeA == 2) {

else if (tubeD == 9 && tubeC == 5 && tubeB == 4 && tubeA == 2) {

AWOL:
The usual problem.

void displayC(){

if (tubeC = 0) {

Usual problem?..

LarryD:
else if (tubeD = 9, tubeC = 5, tubeB = 4, tubeA = 2) {

Also, do you want these to be ORs / ANDs

else if (tubeD == 9 || tubeC == 5 || tubeB == 4 || tubeA == 2) {

else if (tubeD == 9 && tubeC == 5 && tubeB == 4 && tubeA == 2) {

whats the difference/ which one does which, yes I would like it to be and.

nilton61:
If you post your code here it will be easier to help, especially since your link does not work. And please use code brackets for code and url brackets for links in order to help people to help you

sorry, I thought I had posted it earlier, its up now.

You create code brackets by either clicking on the code icon above the text field or starting with the word code within square brackets and ending the code section with /code also in square brackets.

You create url brackets by clicking on the link icon above the text.

If you do so the reader has all information he needs at hand and doesn't need to revert to cut and paste to get the information you are presenting.

And the usual problem in if statements is confusing assignment with test for equality.

whats the difference/ which one does which

The single = is for an assignment as in....

int myPin = 3;

For a comparison though, like in your ifs, you need the double ==.

whats the difference/ which one does which

Do you want a cat AND a dog?

Do you want a cat OR a dog?

Is that clearer?

Ah! but is that an exclusive OR? :grin:

BTW, @OP the code is about four times longer than it needs to be - I strongly urge you to learn how to use arrays.

Code has now been changed with && in the conditions for the count if statement, but it still keeps only outputting 1’s

#include <Event.h>
#include <Timer.h>

Timer t;

// multiplier for time delay, to adjust
int timeModifierNumerator = 1;
int timeModifierDenominator = 1;
// how often to count each minute
long clockTick = 1000*timeModifierNumerator*60/timeModifierDenominator;
// 24 or 12 hour time
int timeType = 12;
int started = 0;

// number for each tube + starting value for time setting
int tubeA = 0;
int tubeB = 0;
int tubeC = 0;
int tubeD = 0;

//pin names!
// tens of hours, 0-2
int oneA = 13;
int twoA = 12;
// units of hours, 0-9
int oneB = 11;
int twoB = 10;
int fourB = 9;
int eightB = 8;
//tens of minutes, 0-6
int oneC = 7;
int twoC = 6;
int fourC = 5;
//units of minutes, 0-9
int oneD = 4;
int twoD = 3;
int fourD = 2;
int eightD = 1;


// setup, output all the things!
void setup(){
 Serial.begin(9600);
 Serial.print("Feed_Started");
 Serial.print('\n');
  pinMode(oneA, OUTPUT);
  pinMode(twoA, OUTPUT);
  pinMode(oneB, OUTPUT);
  pinMode(twoB, OUTPUT);
  pinMode(fourB, OUTPUT);
  pinMode(eightB, OUTPUT);
  pinMode(oneC, OUTPUT);
  pinMode(twoC, OUTPUT);
  pinMode(fourC, OUTPUT);
  pinMode(oneD, OUTPUT);
  pinMode(twoD, OUTPUT);
  pinMode(fourD, OUTPUT);
  pinMode(eightD, OUTPUT);
  
// call count according to timer
t.every(clockTick, count);
  
}

void loop (){
//update timer
t.update();

}

// public loop for generating time
void count(){
Serial.print("minute Counted");
Serial.print('\n');
  // increment minutes
  if (tubeD < 9) {
    tubeD = tubeD+1;
  }
  // increment tens of minutes
  else if (tubeD == 9 && tubeC < 5){
    tubeD = 0;
    tubeC = tubeC + 1;
  }
  // increment hours
  
  // increment hours for first 9 hours
  else if (tubeD == 9 && tubeC == 5 && tubeB < 9 && tubeA == 0){
    tubeD = 0;
    tubeC = 0;
    tubeB = tubeB + 1;
  }
  // increment hours for 12 hour time from 10-12
  else if (tubeD == 9 && tubeC == 5 && tubeA == 1 && timeType == 12 && tubeB < 2){
    tubeD = 0;
    tubeC = 0;
    tubeB = tubeB + 1;
  }
  // increment hours 10-19 if 24 hour time
  else if (tubeD ==9 && tubeC == 5 && tubeA == 1 && timeType == 24 && tubeB < 9){
    tubeD = 0;
    tubeC = 0;
    tubeB = tubeB + 1;
  }
  // increment hours 20-24
  else if (tubeD ==9 && tubeC == 5 && tubeA == 2 && timeType == 24 && tubeB < 4){
    tubeD = 0;
    tubeC = 0;
    tubeB = tubeB + 1;
  }
  
  // increment tens of hours from 0
  else if (tubeD == 9 && tubeC == 5 && tubeB == 9 && tubeA ==0) {
    tubeD = 0;
    tubeC = 0;
    tubeB = 0;
    tubeA = 1;
  }
  // reset clock to 01:00 if twelve hour time
  else if (tubeD == 9 && tubeC == 5 && tubeB == 2 && tubeA ==1 && timeType == 12) {
    tubeD = 0;
    tubeC = 0;
    tubeB = 1;
    tubeA = 0;
  }
  // increment tens of hours if twenty-four hour time
  else if (tubeD == 9 && tubeC == 5 && tubeB == 9 && tubeA == 1 && timeType == 24) {
    tubeD = 0;
    tubeC = 0;
    tubeB = 0;
    tubeA = 2;
  }
  // reset clock to 01:00 if twenty-four hour time
  else if (tubeD == 9 && tubeC == 5 && tubeB == 4 && tubeA == 2) {
    tubeD = 1;
    tubeC = 0;
    tubeB = 0;
    tubeA = 0;
  }
  // cry moment
  else {
  Serial.print("something is broken");
  }
  
  //update time on tubes
  displayA();
  displayB();
  displayC();
  displayD();
  // print current time on tubes for debugging
  Serial.print('\n');
  Serial.print(tubeA);
  Serial.print(tubeB);
  Serial.print(tubeC);
  Serial.print(tubeD);
  Serial.print('\n');
}
// outputs to driver for tube A
void displayA() {
 
  
	if (tubeA = 0) {
	 Serial.print("A0");
  digitalWrite(oneA, LOW);
  digitalWrite(twoA, LOW);
}
else if (tubeA = 1) {
 Serial.print("A1");
  digitalWrite(oneA, HIGH);
  digitalWrite(twoA, LOW);
}
else if (tubeA = 2) {
 Serial.print("A2");
  digitalWrite(oneA, LOW);
  digitalWrite(twoA, HIGH);
}

}

// outputs to driver for tube B
void displayB() {
  

  if (tubeB = 0) {
   Serial.print("B0");
  digitalWrite(oneB, LOW);
  digitalWrite(twoB, LOW);
  digitalWrite(fourB, LOW);
  digitalWrite(eightB, LOW);
}
 else if (tubeB = 1) {
  Serial.print("B1");
  digitalWrite(oneB, HIGH);
  digitalWrite(twoB, LOW);
  digitalWrite(fourB, LOW);
  digitalWrite(eightB, LOW);
}
 else if (tubeB = 2) {
  Serial.print("B2");
  digitalWrite(oneB, LOW);
  digitalWrite(twoB, HIGH);
  digitalWrite(fourB, LOW);
  digitalWrite(eightB, LOW);
}
 else if (tubeB = 3) {
  Serial.print("B3");
  digitalWrite(oneB, HIGH);
  digitalWrite(twoB, HIGH);
  digitalWrite(fourB, LOW);
  digitalWrite(eightB, LOW);
}
 else if (tubeB = 4) {
  Serial.print("B4");
  digitalWrite(oneB, LOW);
  digitalWrite(twoB, LOW);
  digitalWrite(fourB, HIGH);
  digitalWrite(eightB, LOW);
}
 else if (tubeB = 5) {
  Serial.print("B5");
  digitalWrite(oneB, HIGH);
  digitalWrite(twoB, LOW);
  digitalWrite(fourB, HIGH);
  digitalWrite(eightB, LOW);
}
 else if (tubeB = 6) {
  Serial.print("B6");
  digitalWrite(oneB, LOW);
  digitalWrite(twoB, HIGH);
  digitalWrite(fourB, HIGH);
  digitalWrite(eightB, LOW);
}
 else if (tubeB = 7) {
  Serial.print("B7");
  digitalWrite(oneB, HIGH);
  digitalWrite(twoB, HIGH);
  digitalWrite(fourB, HIGH);
  digitalWrite(eightB, LOW);
}
 else if (tubeB = 8) {
  Serial.print("B8");
  digitalWrite(oneB, LOW);
  digitalWrite(twoB, LOW);
  digitalWrite(fourB, LOW);
  digitalWrite(eightB, HIGH);
}
 else if(tubeB = 9) {
  Serial.print("B9");
  digitalWrite(oneB, HIGH);
  digitalWrite(twoB, LOW);
  digitalWrite(fourB, LOW);
  digitalWrite(eightB, HIGH);
}

}

// output to C
void displayC(){
   if (tubeC = 0) {
    Serial.print("C0");
  digitalWrite(oneC, LOW);
  digitalWrite(twoC, LOW);
  digitalWrite(fourC, LOW);
}
  else if (tubeC = 1) {
   Serial.print("C1");
  digitalWrite(oneC, HIGH);
  digitalWrite(twoC, LOW);
  digitalWrite(fourC, LOW);
}
  else if (tubeC = 2) {
   Serial.print("C2");
  digitalWrite(oneC, LOW);
  digitalWrite(twoC, HIGH);
  digitalWrite(fourC, LOW);
}
  else if (tubeC = 3) {
   Serial.print("C3");
  digitalWrite(oneC, HIGH);
  digitalWrite(twoC, HIGH);
  digitalWrite(fourC, LOW);
}
  else if (tubeC = 4) {
   Serial.print("C4");
  digitalWrite(oneC, LOW);
  digitalWrite(twoC, LOW);
  digitalWrite(fourC, HIGH);
}
  else if (tubeC = 5) {
   Serial.print("C5");
  digitalWrite(oneC, HIGH);
  digitalWrite(twoC, LOW);
  digitalWrite(fourC, HIGH);
}
 
}
// output to D
 void displayD() {
  if (tubeD = 0) {
   Serial.print("D0");
  digitalWrite(oneD, LOW);
  digitalWrite(twoD, LOW);
  digitalWrite(fourD, LOW);
  digitalWrite(eightD, LOW);
}
 else if (tubeD = 1) {
  Serial.print("D1");
  digitalWrite(oneD, HIGH);
  digitalWrite(twoD, LOW);
  digitalWrite(fourD, LOW);
  digitalWrite(eightD, LOW);
}
 else if (tubeD = 2) {
  Serial.print("D2");
  digitalWrite(oneD, LOW);
  digitalWrite(twoD, HIGH);
  digitalWrite(fourD, LOW);
  digitalWrite(eightD, LOW);
}
 else if (tubeD = 3) {
  Serial.print("D3");
  digitalWrite(oneD, HIGH);
  digitalWrite(twoD, HIGH);
  digitalWrite(fourD, LOW);
  digitalWrite(eightD, LOW);
}
 else if (tubeD = 4) {
  Serial.print("D4");
  digitalWrite(oneD, LOW);
  digitalWrite(twoD, LOW);
  digitalWrite(fourD, HIGH);
  digitalWrite(eightD, LOW);
}
 else if (tubeD = 5) {
  Serial.print("D5");
  digitalWrite(oneD, HIGH);
  digitalWrite(twoD, LOW);
  digitalWrite(fourD, HIGH);
  digitalWrite(eightD, LOW);
}
 else if (tubeD = 6) {
  Serial.print("D6");
  digitalWrite(oneD, LOW);
  digitalWrite(twoD, HIGH);
  digitalWrite(fourD, HIGH);
  digitalWrite(eightD, LOW);
}
 else if (tubeD = 7) {
  Serial.print("D7");
  digitalWrite(oneD, HIGH);
  digitalWrite(twoD, HIGH);
  digitalWrite(fourD, HIGH);
  digitalWrite(eightD, LOW);
}
 else if (tubeD = 8) {
  Serial.print("D8");
  digitalWrite(oneD, LOW);
  digitalWrite(twoD, LOW);
  digitalWrite(fourD, LOW);
  digitalWrite(eightD, HIGH);
}
 else if (tubeD = 9) {
 Serial.print("D9");
  digitalWrite(oneD, HIGH);
  digitalWrite(twoD, LOW);
  digitalWrite(fourD, LOW);
  digitalWrite(eightD, HIGH);
}
}

the serial print output is just

Feed_Started
minute Counted
A1B1C1D1
1111
minute Counted
A1B1C1D1
1111
minute Counted
A1B1C1D1
1111
minute Counted
A1B1C1D1
1111
minute Counted
A1B1C1D1
1111

forever.

There are still a lot of instances like this:

if (tubeA = 0) {

nilton61:
There are still a lot of instances like this:

if (tubeA = 0) {

Thanks, sorry forgot to check the display functions