Nixie Clock
 Page :   [ 1 ]    [ 2 ]    [ 3 ]    [ 4 ]    [ 5 ]    [ 6 ]  

Heres some simple code that will multiplex the display and show the time.

On the sketches I run theres a lot more code for dimming, buttons, bluetooth and other things but this just illustrates the display working.

I'm using an Atmega1284p with this.

 

#include "RTClib.h"
#include <DS1307RTC.h> 
#include <TimeLib.h>

RTC_DS3231 rtc;
 
#define DRIVER_1_A 23   // K155ID1 Nixie Driver  #1
#define DRIVER_1_B 21   //     "       "
#define DRIVER_1_C 20   //     "       "
#define DRIVER_1_D 22   //     "       "

#define DRIVER_2_A 19   // K155ID1 Nixie Driver #2
#define DRIVER_2_B 13   //     "       "
#define DRIVER_2_C 12   //     "       "
#define DRIVER_2_D 18   //     "       "

// values sent to the nixie drivers to determine which cathode is used and thus which number is displayed
// based on this table from the datasheet
//       Cathode    A B C D
//          0       0 0 0 0
//          1       1 0 0 0 
//          2       0 1 0 0 
//          3       1 1 0 0
//          4       0 0 1 0
//          5       1 0 1 0
//          6       0 1 1 0
//          7       1 1 1 0
//          8       0 0 0 1
//          9       1 0 0 1
//
//                0      1      2      3      4      5      6      7      8      9 .   10(blank, out of range)
int digits[] = {B0000, B1000, B0100, B1100, B0010, B1010, B0110, B1110, B0001, B1001, B1111};

int anodes[] = {27,25,26};    // Anode Pins

// lookup table for the high and low value of mins/sec to determine
// which number needs to be displayed on each of the minutes and seconds tubes
const byte minsec_high[]= {0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5};
const byte minsec_low[] = {0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9};

// lookup table for the high and low value of hours to determine
// which number needs to be displayed on each of the "hours" tubes
const byte hour_high[]= {0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,2,2,2,2};
const byte hour_low[] = {0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3};

volatile long hours = 0;     // variables for holding the value of hours/mins/secs
volatile long minutes = 0;   //                 "                  "
volatile long seconds = 0;   //                 "                  "

void setup() {

  rtc.begin();
  if (rtc.lostPower()) {
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  }

  setSyncProvider(RTC.get);
  if(timeStatus()!= timeSet) {
      // couldnt sync
  } else {
      // sync OK
  }

  pinMode(DRIVER_1_A, OUTPUT);      
  pinMode(DRIVER_1_B, OUTPUT);      
  pinMode(DRIVER_1_C, OUTPUT);      
  pinMode(DRIVER_1_D, OUTPUT);    

  pinMode(DRIVER_2_A, OUTPUT);      
  pinMode(DRIVER_2_B, OUTPUT);      
  pinMode(DRIVER_2_C, OUTPUT);      
  pinMode(DRIVER_2_D, OUTPUT);    

  pinMode(anodes[0], OUTPUT);     
  pinMode(anodes[1], OUTPUT);     
  pinMode(anodes[2], OUTPUT);     
 
}

void showNumbersForAnode(int anode,  int number1, int number2){

  digitalWrite(DRIVER_1_A, bitRead(digits[number1], 3));
  digitalWrite(DRIVER_1_B, bitRead(digits[number1], 2));
  digitalWrite(DRIVER_1_C, bitRead(digits[number1], 1));
  digitalWrite(DRIVER_1_D, bitRead(digits[number1], 0));
  digitalWrite(DRIVER_2_A, bitRead(digits[number2], 3));
  digitalWrite(DRIVER_2_B, bitRead(digits[number2], 2));
  digitalWrite(DRIVER_2_C, bitRead(digits[number2], 1));
  digitalWrite(DRIVER_2_D, bitRead(digits[number2], 0));

  digitalWrite(anode, HIGH); 

  delay(2);

  digitalWrite(anode, LOW);   
   
}


void loop() {
  
  hours = hour();
  minutes = minute();
  seconds = second();

  //  Tubes with their corresponding anodes (A0, A1, A2) and Drivers (1,2)
  //  +---------+  +---------+  +---------+   +---------+  +---------+  +---------+
  //  |         |  |         |  |         |   |         |  |         |  |         |
  //  |   A0    |  |    A1   |  |    A2   |   |   A0    |  |    A1   |  |    A2   |
  //  | Hr High |  |  Hr Low |  | Min High|   |  Min Low|  | Sec High|  | Sec Low |
  //  |         |  |         |  |         |   |         |  |         |  |         |
  //  +---------+--+---------+--+---------+   +---------+--+---------+--+---------+
  //  |                                   |   |                                   |
  //  |            DRIVER 1               |   |            DRIVER 2               |
  //  |                                   |   |                                   |
  //  +-----------------------------------+   +-----------------------------------+
  showNumbersForAnode(anodes[0],hour_high[hours],minsec_low[minutes]);     //  hours High,   minutes Low
  showNumbersForAnode(anodes[1],hour_low[hours],minsec_high[seconds]);     //  hours Low,    seconds High
  showNumbersForAnode(anodes[2],minsec_high[minutes],minsec_low[seconds]); //  minutes High, seconds Low
 
}

(Page 6 of 6)