Close

Test Code

A project log for Modular Nixie Display

Modular nixie display board based on the soviet Russian IN-12A cold-cathode tubes.

johnnyJohnny 01/16/2018 at 03:581 Comment
/*
 * Test File for Modular IN12A Nixie Display Boards
 * Works with Arduino Uno.
 * 
 * By: Johnny Izzard
 */

#include <SPI.h>

#define LD 10
#define CLK 13
#define SDO 11
#define PWM 9

#define tube_off 10
#define ind_off 3

uint16_t decimal_lookup[11] = {0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080, 0x0100, 0x0200, 0x0000}; // decimal_lookup[0]...decimal_lookup[9] outputs corresponding nixie number. decimal_lookup[10] is off.
uint8_t ind_lookup[4] = {0x01, 0x02, 0x03, 0x00}; // ind_lookup[0] is top indicator, ind_lookup[1] is bottom indicator, ind_lookup[2] is both, ind_lookup[3] is off.

uint32_t data1 = 0; // Used to store data to be shifted
uint32_t data2 = 0;
uint32_t data3 = 0;

uint8_t  tube1 = 0; // Value to display on the corresponding tube.
uint8_t  tube2 = 0;
uint8_t  tube3 = 0;
uint8_t  tube4 = 0;
uint8_t  tube5 = 0;
uint8_t  tube6 = 0;

uint8_t indicator1 = 0; // Value to display on the corresponding indicator. 
uint8_t indicator2 = 0;
uint8_t indicator3 = 0;


void setup() {
  
  pinMode(LD,OUTPUT);  // LD is pin 10 (active high)
  pinMode(CLK,OUTPUT); // CLK is pin 13
  pinMode(SDO,OUTPUT); // SDO is pin 11
  pinMode(PWM,OUTPUT); // PWM (Blank) is pin 9 (active low)
  digitalWrite(LD,LOW);
  digitalWrite(CLK,LOW);
  digitalWrite(SDO,LOW);
  digitalWrite(PWM,HIGH);
  SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE1));

  /* Reset Values/Blank The Display */
  tube1 = tube_off;
  tube2 = tube_off;
  tube3 = tube_off;
  tube4 = tube_off;
  tube5 = tube_off;
  tube6 = tube_off;
  indicator1 = ind_off;
  indicator2 = ind_off;
  indicator3 = ind_off;
  update_disp();
}

void loop() {

  indicator1 = 2; // Both indicators on
  indicator2 = 2;
  indicator3 = ind_off;
  for(uint8_t i = 0; i<10; i++){
    tube1 = i;
    tube2 = i;
    tube3 = i;
    tube4 = i;
    tube5 = i;
    tube6 = i;
    update_disp();
    delay(500);
  }

  /* Reset Values/Blank The Display */
  tube1 = tube_off;
  tube2 = tube_off;
  tube3 = tube_off;
  tube4 = tube_off;
  tube5 = tube_off;
  tube6 = tube_off;
  indicator1 = ind_off;
  indicator2 = ind_off;
  indicator3 = ind_off;
  update_disp();
  delay(500);

  tube1 = 9;
  update_disp();
  delay(500);

  tube1 = tube_off;
  tube2 = 9;
  update_disp();
  delay(500);

  tube2 = tube_off;
  indicator1 = 0;
  update_disp();
  delay(500);

  indicator1 = 1;
  update_disp();
  delay(500);

  indicator1 = 2;
  update_disp();
  delay(500);

  indicator1 = ind_off;
  tube3 = 9;
  update_disp();
  delay(500);

  tube3 = tube_off;
  tube4 = 9;
  update_disp();
  delay(500);

  tube4 = tube_off;
  indicator2 = 0;
  update_disp();
  delay(500);

  indicator2 = 1;
  update_disp();
  delay(500);

  indicator2 = 2;
  update_disp();
  delay(500);

  indicator2 = ind_off;
  tube5 = 9;
  update_disp();
  delay(500);

  tube5 = tube_off;
  tube6 = 9;
  update_disp();
  delay(500);

  tube6 = tube_off;
  indicator3 = 0;
  update_disp();
  delay(500);

  indicator3 = 1;
  update_disp();
  delay(500);

  indicator3 = 2;
  update_disp();
  delay(500);

  indicator3 = ind_off;
  update_disp();
  delay(500);

  // All On
  tube1 = 9;
  tube2 = 9;
  tube3 = 9;
  tube4 = 9;
  tube5 = 9;
  tube6 = 9;
  indicator1 = 2;
  indicator2 = 2;
  indicator3 = 2;
  update_disp();

  // Fade Out
  for(uint8_t i = 150; i!=0; i-=1){
    analogWrite(PWM,i);
    delay(40);
  }

  // Fade In
  for(uint8_t i = 0; i!=150; i+=1){
    analogWrite(PWM,i);
    delay(40);
  }
  digitalWrite(PWM,HIGH);

  
}

void update_disp(void){
  data1 = 0x00000000;
  data1 |= ((uint32_t (decimal_lookup[tube1]))&0x000003FF);
  data1 |= ((uint32_t (decimal_lookup[tube2])<<10)&0x000FFC00); 
  data1 |= ((uint32_t (ind_lookup[indicator1])<<20)&0x00300000);

  data2 = 0x00000000;
  data2 |= ((uint32_t (decimal_lookup[tube3]))&0x000003FF);
  data2 |= ((uint32_t (decimal_lookup[tube4])<<10)&0x000FFC00); 
  data2 |= ((uint32_t (ind_lookup[indicator2])<<20)&0x00300000);

  data3 = 0x00000000;
  data3 |= ((uint32_t (decimal_lookup[tube5]))&0x000003FF);
  data3 |= ((uint32_t (decimal_lookup[tube6])<<10)&0x000FFC00); 
  data3 |= ((uint32_t (ind_lookup[indicator3])<<20)&0x00300000); 

  digitalWrite(LD,HIGH);
  SPI.transfer(data1>>24);
  SPI.transfer(data1>>16);
  SPI.transfer(data1>>8);
  SPI.transfer(data1);
  digitalWrite(LD,LOW);
  digitalWrite(LD,HIGH);
  
  digitalWrite(LD,HIGH);
  SPI.transfer(data2>>24);
  SPI.transfer(data2>>16);
  SPI.transfer(data2>>8);
  SPI.transfer(data2);
  digitalWrite(LD,LOW);
  digitalWrite(LD,HIGH);

  digitalWrite(LD,HIGH);
  SPI.transfer(data3>>24);
  SPI.transfer(data3>>16);
  SPI.transfer(data3>>8);
  SPI.transfer(data3);
  digitalWrite(LD,LOW);
  digitalWrite(LD,HIGH);
}

Discussions

Jay wrote 11/15/2019 at 21:34 point

This is really useful work. Thanks for for the awesome write up.

  Are you sure? yes | no