 # Nixe tube clock sketch Hello, I’m trying to modify this piece of code originally written for a nixie tube clock. The clock uses 4 nixie tubes to show hours & minutes but I wish to add 2 extra tubes to show the seconds as well. Can someone point me in the right direction as to which parts of the code to modify and some hints on how??

``````/*
Nixie tube demonstration code - simple clock
http://tronixstuff.com - John Boxall. February 2011.
Baseon on a sketch originally created by Lionel Haims, July 25, 2008.
Released into the public domain.
*/

#include "Wire.h"
#include "Nixie.h"

// note the digital pins of the arduino that are connected to the nixie driver
#define dataPin 2  // data line or SER
#define clockPin 3 // clock pin or SCK
#define latchPin 4 // latch pin or RCK

// note the number of digits (nixie tubes) you have (buy more, you need more!)
#define numDigits 4

int narray[numDigits]; // holds the digits to display
int a=0;

// Create the Nixie object
// pass in the pin numbers in the correct order
Nixie nixie(dataPin, clockPin, latchPin);

// Convert normal decimal numbers to binary coded decimal
byte decToBcd(byte val)
{
return ( (val/10*16) + (val%10) );
}

// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val)
{
return ( (val/16*10) + (val%16) );
}

void setDateDs1307(byte second,        // 0-59
byte minute,        // 0-59
byte hour,          // 1-23
byte dayOfWeek,     // 1-7
byte dayOfMonth,    // 1-28/29/30/31
byte month,         // 1-12
byte year)          // 0-99
{
Wire.send(0);
Wire.send(decToBcd(second));    // 0 to bit 7 starts the clock
Wire.send(decToBcd(minute));
Wire.send(decToBcd(hour));
Wire.send(decToBcd(dayOfWeek));
Wire.send(decToBcd(dayOfMonth));
Wire.send(decToBcd(month));
Wire.send(decToBcd(year));
Wire.send(0x10); // sends 0x10 (hex) 00010000 (binary) to control register - turns on square wave
Wire.endTransmission();
}

// Gets the date and time from the ds1307
void getDateDs1307(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)
{
// Reset the register pointer
Wire.send(0);
Wire.endTransmission();
// A few of these need masks because certain bits are control bits
*hour       = bcdToDec(Wire.receive() & 0x3f);  // Need to change this if 12 hour am/pm
}

void setup()
{
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
Wire.begin();
nixie.clear(numDigits); // clear display

// Change these values to what you want to set your clock to.
// You probably only want to set your clock once and then remove
// the setDateDs1307 call.

second = 45;
minute = 59;
hour = 23;
dayOfWeek = 5;
dayOfMonth = 26;
month = 2;
year = 11;
setDateDs1307(second, minute, hour, dayOfWeek, dayOfMonth, month, year);
}

void nixNum(int z)
// displays integer 'z' on 4-digit nixe display
// keeps leading zero, as blank still flickers somewhat
{
narray=int(z/1000); // thousands value
z=z-(narray*1000);
narray=int(z/100); // hundreds value
z=z-(narray*100);
narray=int(z/10); // tens value
narray=z-(narray*10); // ones value
nixie.writeArray( narray, numDigits);
}

void showTime()
{
int zzz=0;
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
if (bcdToDec(hour)<1)
{
zzz=minute;
}
else if (bcdToDec(hour)>=1)
{
zzz=hour*100;
zzz=zzz+minute;
}
nixNum(zzz);
}

void showDate()
{
int zzz=0;
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
zzz=(dayOfMonth*100)+month;
nixNum(zzz);
}

void loop()
{
showTime(); // display the time
delay(1000);
a++;
if (a==10)
{
showDate(); // display the date (day and month) for two seconds
delay(2000);
a=1;
}
}
``````

From what I understand, after changing the “define numDigits” to 6 I then need to add a “narray” 4 & 5 here?

``````{
narray=int(z/1000); // thousands value
z=z-(narray*1000);
narray=int(z/100); // hundreds value
z=z-(narray*100);
narray=int(z/10); // tens value
narray=z-(narray*10); // ones value
nixie.writeArray( narray, numDigits);
}
``````

and then play with the “if” statement?

`````` if (bcdToDec(hour)<1)
{
zzz=minute;
}
else if (bcdToDec(hour)>=1)
{
zzz=hour*100;
zzz=zzz+minute;
}
nixNum(zzz);
}
``````

Thanks for any help at all You are going to need to post a schematic or a link so we could see what the hardware is.

:) Thanks kf2qd!

My hardware is exactly the same as in the article.

I assume that you already know how to expand the display with the shift registers and all.

The code changes should be about the same.

You will need to increases the size of the array which holds the digits (narray to narray).

You will need to add code to

``````{
narray=int(z/100000); // hundred thousands value
z=z-(narray*100000);
narray=int(z/10000); // ten thousands value
z=z-(narray*10000);
narray=int(z/1000); // thousands value
z=z-(narray*1000);
narray=int(z/100); // hundreds value
z=z-(narray*100);
narray=int(z/10); // tens value
narray=z-(narray*10); // ones value
``````

I might have coded it a different way

``````for (int i=numDigits-1; i>=0; i--) {
narray[i] = z%10;
z /= 10;
}
``````

But that's just me.