Trying to make a simple Lixie clock and cant Figure out the code

I have tried to use a Arduino mega to create a 4 digit Lixie clock and cant figure out the code. If someone could please help me find out whats wrong with my code.

const int m1D0 = 1; //m1 is the 1 minute digit and the D is the number
const int m1D1 = 2;
const int m1D2 = 3;
const int m1D3 = 4;
const int m1D4 = 5;
const int m1D5 = 6;
const int m1D6 = 7;
const int m1D7 = 8;
const int m1D8 = 9;
const int m1D9 = 10;
const int m10D0 = 11; //m10 is the tens digit place
const int m10D1 = 12;
const int m10D2 = 13;
const int m10D3 = 14;
const int m10D4 = 15;
const int m10D5 = 16;
const int m10D6 = 17;
const int m10D7 = 18;
const int m10D8 = 19;
const int m10D9 = 20;
const int h1D0 = 21; h1 is the 1 hour digit
const int h1D1 = 22;
const int h1D2 = 23;
const int h1D3 = 24;
const int h1D4 = 25;
const int h1D5 = 26;
const int h1D6 = 27;
const int h1D7 = 28;
const int h1D8 = 29;
const int h1D9 = 30;
const int h10D0 = 31; //h10 is the 10 hour digit
const int h10D1 = 32;
const int h10D2 = 33;
const int h10D3 = 34;
const int h10D4 = 35;
const int h10D5 = 36;
const int h10D6 = 37;
const int h10D7 = 38;
const int h10D8 = 39;
const int h10D9 = 40;
int min1; //integers that hold the numbers
int min10;
int hour1;
int hour10;

void setup() {
pinMode(m1D0, OUTPUT);
pinMode(m1D1, OUTPUT);
pinMode(m1D2, OUTPUT);
pinMode(m1D3, OUTPUT);
pinMode(m1D4, OUTPUT);
pinMode(m1D5, OUTPUT);
pinMode(m1D6, OUTPUT);
pinMode(m1D7, OUTPUT);
pinMode(m1D8, OUTPUT);
pinMode(m1D9, OUTPUT);
pinMode(m10D0, OUTPUT);
pinMode(m10D1, OUTPUT);
pinMode(m10D2, OUTPUT);
pinMode(m10D3, OUTPUT);
pinMode(m10D4, OUTPUT);
pinMode(m10D5, OUTPUT);
pinMode(m10D6, OUTPUT);
pinMode(m10D7, OUTPUT);
pinMode(m10D8, OUTPUT);
pinMode(m10D9, OUTPUT);
pinMode(h1D0, OUTPUT);
pinMode(h1D1, OUTPUT);
pinMode(h1D2, OUTPUT);
pinMode(h1D3, OUTPUT);
pinMode(h1D4, OUTPUT);
pinMode(h1D5, OUTPUT);
pinMode(h1D6, OUTPUT);
pinMode(h1D7, OUTPUT);
pinMode(h1D8, OUTPUT);
pinMode(h1D9, OUTPUT);
pinMode(h10D0, OUTPUT);
pinMode(h10D1, OUTPUT);
pinMode(h10D2, OUTPUT);
pinMode(h10D3, OUTPUT);
pinMode(h10D4, OUTPUT);
pinMode(h10D5, OUTPUT);
pinMode(h10D6, OUTPUT);
pinMode(h10D7, OUTPUT);
pinMode(h10D8, OUTPUT);
pinMode(h10D9, OUTPUT);
hour10 = 1; //sets the initial time
hour1 = 2;
min10 = 0;
min1 = 0;
}

void loop() {

if (min1 > 9) { //if the min1 integer is higher than 9 then set min1 to 0 and add 1 to min10
min10 = min10 + 1;
min1 = 0;
} else {
}

if (min10 > 5) { //if min10 is higher than 5 then set min10 to 0 and add 1 to hour1
hour1 = hour1 + 1;
min10 = 0;
} else {
}

if (hour1 > 9) { //if hour1 is higher than 9 then add one to hour10 and set hour1 to 0
hour10 = 1;
} else {
hour10 = 0;
}

if (hour1 > 12) {
hour10 = 0;
hour1 = 1;
} else {
}

if (min1 = 0) { // the rest of the code is for turning on the LEDs
digitalWrite(m1D0, HIGH);
} else {
digitalWrite(m1D0, LOW);
}

if (min1 = 1) {
digitalWrite(m1D1, HIGH);
} else {
digitalWrite(m1D1, LOW);
}

if (min1 = 2) {
digitalWrite(m1D2, HIGH);
} else {
digitalWrite(m1D2, LOW);
}

if (min1 = 3) {
digitalWrite(m1D3, HIGH);
} else {
digitalWrite(m1D3, LOW);
}

if (min1 = 4) {
digitalWrite(m1D4, HIGH);
} else {
digitalWrite(m1D4, LOW);
}

if (min1 = 5) {
digitalWrite(m1D5, HIGH);
} else {
digitalWrite(m1D5, LOW);
}

if (min1 = 6) {
digitalWrite(m1D6, HIGH);
} else {
digitalWrite(m1D6, LOW);
}

if (min1 = 7) {
digitalWrite(m1D7, HIGH);
} else {
digitalWrite(m1D7, LOW);
}

if (min1 = 8) {
digitalWrite(m1D8, HIGH);
} else {
digitalWrite(m1D8, LOW);
}

if (min1 = 9) {
digitalWrite(m1D9, HIGH);
} else {
digitalWrite(m1D9, LOW);
}

if (min10 = 0) {
digitalWrite(m1D0, HIGH);
} else {
digitalWrite(m1D0, LOW);
}

if (min10 = 1) {
digitalWrite(m1D1, HIGH);
} else {
digitalWrite(m1D1, LOW);
}

if (min10 = 2) {
digitalWrite(m1D2, HIGH);
} else {
digitalWrite(m1D2, LOW);
}

if (min10 = 3) {
digitalWrite(m1D3, HIGH);
} else {
digitalWrite(m1D3, LOW);
}

if (min10 = 4) {
digitalWrite(m1D4, HIGH);
} else {
digitalWrite(m1D4, LOW);
}

if (min10 = 5) {
digitalWrite(m1D5, HIGH);
} else {
digitalWrite(m1D5, LOW);
}

if (min10 = 6) {
digitalWrite(m1D6, HIGH);
} else {
digitalWrite(m1D6, LOW);
}

if (min10 = 7) {
digitalWrite(m1D7, HIGH);
} else {
digitalWrite(m1D7, LOW);
}

if (min10 = 8) {
digitalWrite(m1D8, HIGH);
} else {
digitalWrite(m1D8, LOW);
}

if (min10 = 9) {
digitalWrite(m1D9, HIGH);
} else {
digitalWrite(m1D9, LOW);
}

if (hour1 = 0) {
digitalWrite(h1D0, HIGH);
} else {
digitalWrite(h1D0, LOW);
}

if (hour1 = 1) {
digitalWrite(h1D1, HIGH);
} else {
digitalWrite(h1D1, LOW);
}

if (hour1 = 2) {
digitalWrite(h1D2, HIGH);
} else {
digitalWrite(h1D2, LOW);
}

if (hour1 = 3) {
digitalWrite(h1D3, HIGH);
} else {
digitalWrite(h1D3, LOW);
}

if (hour1 = 4) {
digitalWrite(h1D4, HIGH);
} else {
digitalWrite(h1D4, LOW);
}

if (hour1 = 5) {
digitalWrite(h1D5, HIGH);
} else {
digitalWrite(h1D5, LOW);
}

if (hour1 = 6) {
digitalWrite(h1D6, HIGH);
} else {
digitalWrite(h1D6, LOW);
}

if (hour1 = 7) {
digitalWrite(h1D7, HIGH);
} else {
digitalWrite(h1D7, LOW);
}

if (hour1 = 8) {
digitalWrite(h1D8, HIGH);
} else {
digitalWrite(h1D8, LOW);
}

if (hour1 = 9) {
digitalWrite(h1D9, HIGH);
} else {
digitalWrite(h1D9, LOW);
}

if (hour10 = 0) {
digitalWrite(h10D0, HIGH);
} else {
digitalWrite(h10D0, LOW);
}

if (hour10 = 1) {
digitalWrite(h10D1, HIGH);
} else {
digitalWrite(h10D1, LOW);
}

if (hour10 = 2) {
digitalWrite(h10D2, HIGH);
} else {
digitalWrite(h10D2, LOW);
}

if (hour10 = 3) {
digitalWrite(h10D3, HIGH);
} else {
digitalWrite(h10D3, LOW);
}

if (hour10 = 4) {
digitalWrite(h10D4, HIGH);
} else {
digitalWrite(h10D4, LOW);
}

if (hour10 = 5) {
digitalWrite(h10D5, HIGH);
} else {
digitalWrite(h10D5, LOW);
}

if (hour10 = 6) {
digitalWrite(h10D6, HIGH);
} else {
digitalWrite(h10D6, LOW);
}

if (hour10 = 7) {
digitalWrite(h10D7, HIGH);
} else {
digitalWrite(h10D7, LOW);
}

if (hour10 = 8) {
digitalWrite(h10D8, HIGH);
} else {
digitalWrite(h10D8, LOW);
}

if (hour10 = 9) {
digitalWrite(h10D9, HIGH);
} else {
digitalWrite(h10D9, LOW);
}

delay(60000); //wait 1 minute
min1 = min1 + 1; //add 1 to min1
}

I'm using a mega because it has 53 digital pins and I need at least 40 to make this work.

Please edit your post to add code tags. Explain what the code should do, and what it does instead.

Code tag example:

if (hour10 = 7) {

Note that "=" is the assignment operator. "==" is used for comparisons.

Do you mean "Nixie" clock?

I thought of this too at first... and so did Google, lol.
Check this.

Check this

Ugh.

That is a huge program but you could crush it down to a few lines by creating arrays for the pin groups and for() loops.
Also make it more accurate by using the Arduino TimeLib library instead of driving it by delay with a few more lines.

Well I think it looks quite effective. Having said that I would prefer a Nixie clock having now built 3 and acquired the components for 2 more, while tubes are still obtainable.

Hi, @Masterpatches01
Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum".

What is the problem, does it compile?
Why have you written so much to find the problem.
Have you written your code in stages?
If you have then you know at what point the problem occurred?

What model Arduino are you using?

Can you please tell us your electronics, programming, arduino, hardware experience?

Thanks.. Tom... :grinning: :+1: :coffee: :australia:

He is using Arduino Mega.
His mistake is that he used the assignment sign "=" instead of equality "==" in the if()'s

timeChangeHour and timeChangeMins are not decared for a start.

Tom... :grinning: :+1: :coffee: :australia:

Looking at the picture of the clock, it does seem possible to tell the time.

Hello
your sketch is calling for array´s and struct{}´s.

I guess that when you get the code in a compilable, then working state, you'll soon notice that the clock runs a little fast.
But, I suggest you get it working before considering all the optimisation suggestions you are receiving here.

Try to group a lot of code in functions or for-loops. You could make a pin-array instead of all those separate consts.

byte pinMap[4][10]={
{0,1,2,3,4,5,6,7,8,9},
{...},
{...},
{...}
};

Setting pins to OUTPUT would then become:

for (byte n=0;n<40;n++){
  pinMode(pinMap[n/10][n%10],OUTPUT);
}

Instead of 40 identical lines of code.

But, you could do the same with a smaller Arduino, a Nixie tube can easily be multiplexed: use 4 pins to switch one of the tubes, and 10 pins to select the digit, so 14 pins for 40 numbers! If you cycle like 100 times per second, nobody sees the flickering.

Jeepers, you must like making things difficult for yourself!

Let the compiler take the strain

for (auto& row : pinMap) {
  for (auto& col : row) {
    pinMode (col, OUTPUT);
  }
}

Hi,

It sounds like you didn't write the code.
If not can you post a link to the site?

Thanks... Tom.... :grinning: :+1: :coffee: :australia:

I bet it is more efficient, but readability for noobs is close to 0. For example, I have no idea why "col" would suffice as pin number variable in this case. This is cryptic C++ cheese.

Does this work?

for (int n: pinMap){
  pinMode (n,OUTPUT)
}

Has better readability IMO. Or do you really have to nest 2 loops? Would be nice if you can flatten rectangular or cubic arrays. Thanks for pointing out the array loops though, they are indeed useful.

Hi,
I think we now need to wait for @Masterpatches01 to reply...

Tom... :grinning: :+1: :coffee: :australia:

Ok, thanks for the advice and I meant to say Lixie clock. A lixie clock is a simpler and more modern version of the Nixie clock. it uses LEDs shining under a laser engraved Plexiglas piece.

Oh, yeah I used that delay for testing and forgot to change it back to 1 minute.

And a liberal dose of modulo arithmetic is? :open_mouth:
(And yes, it does result in smaller code - like I said, let the compiler take the strain)
Remember, everything is cryptic to the noob.

It may compile, with warnings, but it won't work.

Yes, you should write nested loops - the array is, after all, nested.