Hey!
I´m new with arduino and want to programm a 6 digit nixie clock.
I am using 6 Bulbs 6 driver ic´s SN74141 a arduino mega and a ds1307 real time clock.
Each driver has 4 bcd inputs (ABCD , 1 2 4 8 ).
I only need help with the programm.
I already found a tutorial where you can get the time from the rtc
like 1 byte for secounds ,1 for minutes,1 for hours.
So my question is can i read 1 nibble (4 bit) for lower secounds and 1 nibble for higher? (same for minutes and hours)
And could you say this nibble equals 4 outputs so that the output would have the truth table of the nibble? ( Nibble 0101 = outputs 1-4 0101)
Is this possible?
If not i thougt to do something like this to display 21secounds:
if (lowersecounds == 1) //write 1000
{
digitalWrite(A, HIGH);
digitalWrite(B, LOW;
digitalWrite(C, LOW);
digitalWrite(D, LOW);
}
if (highersecounds == 2) //write 0100
{
digitalWrite(A, LOW);
digitalWrite(B, HIGH;
digitalWrite(C, LOW);
digitalWrite(D, LOW);
}
Thanks for help and sorry english isn´t my native language!
Bob
I will post my newest code everytime in here:
//Nixie Clock Programm
//Designed for 6 bulbs with 6 SN74141/K155id1 drivers
//Driven by an Arduino Mega with an DS1307 RTC
//Base RTC code was from here: http://tronixstuff.com/2014/12/01/tutorial-using-ds1307-and-ds3231-real-time-clock-modules-with-arduino/
//Truthtable SN74141/K155id1:
//D C B A
//0 0 0 0 = 0
//0 0 0 1 = 1
//0 0 1 0 = 2
//0 0 1 1 = 3
//0 1 0 0 = 4
//0 1 0 1 = 5
//0 1 1 0 = 6
//0 1 1 1 = 7
//1 0 0 0 = 8
//1 0 0 1 = 9
//1 0 1 0 = NONE
//1 0 1 1 = NONE
//1 1 0 0 = NONE
//1 1 0 1 = NONE
//1 1 1 0 = NONE
//1 1 1 1 = NONE
#include "Wire.h"
#define DS1307_I2C_ADDRESS 0x68
//Define the input buttons here
int plusMin = 3;
int plusHr = 4;
int minusMin = 5;
int minusHr = 6;
// 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 setup()
{
Wire.begin();
Serial.begin(9600);
// set the initial time here:
// DS1307 seconds, minutes, hours, day, date, month, year
// setDS1307time(30,42,21,4,26,11,14);
//Defining The Ports
pinMode(plusMin, INPUT);
pinMode(plusHr, INPUT);
pinMode(minusMin, INPUT);
pinMode(minusHr, INPUT);
DDRA = B11111111;
DDRC = B11111111;
DDRK = B11111111;
}
//Time setting Function
void setDS1307time(byte second, byte minute, byte hour, byte dayOfWeek, byte
dayOfMonth, byte month, byte year)
{
// sets time and date data to DS3231
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.write(0); // set next input to start at the seconds register
Wire.write(decToBcd(second)); // set seconds
Wire.write(decToBcd(minute)); // set minutes
Wire.write(decToBcd(hour)); // set hours
Wire.write(decToBcd(dayOfWeek)); // set day of week (1=Sunday, 7=Saturday)
Wire.write(decToBcd(dayOfMonth)); // set date (1 to 31)
Wire.write(decToBcd(month)); // set month
Wire.write(decToBcd(year)); // set year (0 to 99)
Wire.endTransmission();
}
//Reading the time
void readDS1307time(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)
{
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.write(0); // set DS1307 register pointer to 00h
Wire.endTransmission();
Wire.requestFrom(DS1307_I2C_ADDRESS, 7);
// request seven bytes of data from DS3231 starting from register 00h
*second = Wire.read() & 0x7f; //maybe delete the 0x7f
*minute = Wire.read();
*hour = Wire.read() & 0x3f; //maybe delete the 0x3f
*dayOfWeek = Wire.read();
*dayOfMonth = Wire.read();
*month = Wire.read();
*year = Wire.read();
}
void AntiCathodePoisoning(){
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year, ACP;
//If minutes equals 15 or 45
if ((bcdToDec(minute) == 15 || bcdToDec(minute) == 45) && decToBcd(second) <= 5){
ACP = ACP + 1;
PORTA = B00000000;
PORTC = B00000000;
PORTK = B00000000;
delay(100);
PORTA = B00010001;
PORTC = B00010001;
PORTK = B00010001;
delay(100);
PORTA = B00100010;
PORTC = B00100010;
PORTK = B00100010;
delay(100);
PORTA = B00110011;
PORTC = B00110011;
PORTK = B00110011;
delay(100);
PORTA = B01000100;
PORTC = B01000100;
PORTK = B01000100;
delay(100);
PORTA = B01010101;
PORTC = B01010101;
PORTK = B01010101;
delay(100);
PORTA = B01100110;
PORTC = B01100110;
PORTK = B01100110;
delay(100);
PORTA = B01110111;
PORTC = B01110111;
PORTK = B01110111;
delay(100);
PORTA = B10001000;
PORTC = B10001000;
PORTK = B10001000;
delay(100);
PORTA = B10011001;
PORTC = B10011001;
PORTK = B10011001;
delay(100);
}
else{
ACP = 0;
}
}
//get the time to the outputs
void displayTime()
{
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year, ACP;
// retrieve data from DS3231
readDS1307time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
//Not showing the time between 03-05 Am or during AntiCathodePoisoning routine
if (!bcdToDec(hour) == 03 && !bcdToDec(hour) == 04 && !bcdToDec(hour) == 05 && !ACP == 1) {
//Write the time to the pins (maybe put them in the loop)
//Pin 22-29
PORTA = second;
//Pin 30-37
PORTC = minute;
//Pin A8-A15
PORTK = hour;
}
else if ((bcdToDec(hour) == 03 || bcdToDec(hour) || 04 || bcdToDec(hour) == 05) && ACP == 0){
// BCD 1111 equals 15 in DEC. 15 is converted in the driver as bulb turned off
PORTA = B11111111;
PORTC = B11111111;
PORTK = B11111111;
}
delay(10); // 10ms because the internal time counting could be not accurate
}
//Setting the time via Buttons
//if you hold the button it will repeat it´s action every 0,5 seconds
void Buttons()
{
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year, Min_set, Hr_set;
//Setting the time via Buttons
if (digitalRead(minusMin) == HIGH) {
Min_set = bcdToDec(minute) - 1;
if(Min_set == -1){
Min_set == 59;
}
setDS1307time(bcdToDec(second), Min_set, bcdToDec(hour), bcdToDec(dayOfWeek), bcdToDec(dayOfMonth), bcdToDec(month), bcdToDec(year));
delay(500);
}
if (digitalRead(plusMin) == HIGH) {
Min_set = bcdToDec(minute) + 1;
if(Min_set == 60){
Min_set == 00;
}
setDS1307time(bcdToDec(second), Min_set, bcdToDec(hour), bcdToDec(dayOfWeek), bcdToDec(dayOfMonth), bcdToDec(month), bcdToDec(year));
delay(500);
}
if (digitalRead(minusHr) == HIGH) {
Hr_set = bcdToDec(hour) - 1;
if(Hr_set == 0){
Hr_set = 24;
}
setDS1307time(bcdToDec(second), bcdToDec(minute), Hr_set, bcdToDec(dayOfWeek), bcdToDec(dayOfMonth), bcdToDec(month), bcdToDec(year));
delay(500);
}
if (digitalRead(plusHr) == HIGH) {
Hr_set = bcdToDec(hour) + 1;
if(Hr_set == 25){
Hr_set = 1;
}
setDS1307time(bcdToDec(second), bcdToDec(minute), Hr_set, bcdToDec(dayOfWeek), bcdToDec(dayOfMonth), bcdToDec(month), bcdToDec(year));
delay(500);
}
}
void loop()
{
displayTime();
Buttons();
AntiCathodePoisoning();
}