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"
#define DS1307_I2C_ADDRESS 0x68
// 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.beginTransmission(DS1307_I2C_ADDRESS);
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.beginTransmission(DS1307_I2C_ADDRESS);
Wire.send(0);
Wire.endTransmission();
Wire.requestFrom(DS1307_I2C_ADDRESS, 7);
// A few of these need masks because certain bits are control bits
*second = bcdToDec(Wire.receive() & 0x7f);
*minute = bcdToDec(Wire.receive());
*hour = bcdToDec(Wire.receive() & 0x3f); // Need to change this if 12 hour am/pm
*dayOfWeek = bcdToDec(Wire.receive());
*dayOfMonth = bcdToDec(Wire.receive());
*month = bcdToDec(Wire.receive());
*year = bcdToDec(Wire.receive());
}
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[0]=int(z/1000); // thousands value
z=z-(narray[0]*1000);
narray[1]=int(z/100); // hundreds value
z=z-(narray[1]*100);
narray[2]=int(z/10); // tens value
narray[3]=z-(narray[2]*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[0]=int(z/1000); // thousands value
z=z-(narray[0]*1000);
narray[1]=int(z/100); // hundreds value
z=z-(narray[1]*100);
narray[2]=int(z/10); // tens value
narray[3]=z-(narray[2]*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 ![]()