I'm working on a project that uses an arduino to create a stock ticker on 6 Nixie tubes. The stock price is being scrapes and sent to the arduino via pi. I have code for a four tube display. Was wondering if anyone could help me transform that into a six tube display. Any help would be greatly appreciated. Here's the initial code.
//this is based on the Arduinix 6-digit clock code. It includes code to drive
//the Adafruit I2C 128x32 OLED display for debug purposes.
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 14
Adafruit_SSD1306 display(OLED_RESET);
// SN74141 (1)
int ledPin_0_a = 2;
int ledPin_0_b = 3;
int ledPin_0_c = 4;
int ledPin_0_d = 5;
// SN74141 (2)
int ledPin_1_a = 6;
int ledPin_1_b = 7;
int ledPin_1_c = 8;
int ledPin_1_d = 9;
// anode pins
int ledPin_a_1 = 10;
int ledPin_a_2 = 11;
int ledPin_a_3 = 12;
void setup()
{
pinMode(ledPin_0_a, OUTPUT);
pinMode(ledPin_0_b, OUTPUT);
pinMode(ledPin_0_c, OUTPUT);
pinMode(ledPin_0_d, OUTPUT);
pinMode(ledPin_1_a, OUTPUT);
pinMode(ledPin_1_b, OUTPUT);
pinMode(ledPin_1_c, OUTPUT);
pinMode(ledPin_1_d, OUTPUT);
pinMode(ledPin_a_1, OUTPUT);
pinMode(ledPin_a_2, OUTPUT);
pinMode(ledPin_a_3, OUTPUT);
Serial.begin(19200);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C...
// ...for the 128x32 OLED display
display.clearDisplay(); // set up I2C display
display.setTextSize(2);
display.setTextColor(WHITE);
}
void DisplayNumberSet( int anod, int num1, int num2 )
{
int anodPin;
int a,b,c,d;
// set defaults to blank display
a=1;
b=1;
c=1;
d=1;
anodPin = ledPin_a_1; // default on first anode.
// Select what anod to fire.
switch( anod )
{
case 0:
anodPin = ledPin_a_1;
break;
case 1:
anodPin = ledPin_a_2;
break;
case 2:
anodPin = ledPin_a_3;
break;
}
// Load the a,b,c,d.. to send to the SN74141 IC (1)
switch( num1 )
{
case 0:
a=0;
b=0;
c=0;
d=0;
break;
case 1:
a=1;
b=0;
c=0;
d=0;
break;
case 2:
a=0;
b=1;
c=0;
d=0;
break;
case 3:
a=1;
b=1;
c=0;
d=0;
break;
case 4:
a=0;
b=0;
c=1;
d=0;
break;
case 5:
a=1;
b=0;
c=1;
d=0;
break;
case 6:
a=0;
b=1;
c=1;
d=0;
break;
case 7:
a=1;
b=1;
c=1;
d=0;
break;
case 8:
a=0;
b=0;
c=0;
d=1;
break;
case 9:
a=1;
b=0;
c=0;
d=1;
break;
case 10:
a=1;
b=1;
c=1;
d=1;
}
// Write to output pins.
digitalWrite(ledPin_0_d, d);
digitalWrite(ledPin_0_c, c);
digitalWrite(ledPin_0_b, b);
digitalWrite(ledPin_0_a, a);
// Load the a,b,c,d.. to send to the SN74141 IC (2)
switch( num2 )
{
case 0:
a=0;
b=0;
c=0;
d=0;
break;
case 1:
a=1;
b=0;
c=0;
d=0;
break;
case 2:
a=0;
b=1;
c=0;
d=0;
break;
case 3:
a=1;
b=1;
c=0;
d=0;
break;
case 4:
a=0;
b=0;
c=1;
d=0;
break;
case 5:
a=1;
b=0;
c=1;
d=0;
break;
case 6:
a=0;
b=1;
c=1;
d=0;
break;
case 7:
a=1;
b=1;
c=1;
d=0;
break;
case 8:
a=0;
b=0;
c=0;
d=1;
break;
case 9:
a=1;
b=0;
c=0;
d=1;
break;
case 10:
a=1;
b=1;
c=1;
d=1;
}
// Write to output pins
digitalWrite(ledPin_1_d, d);
digitalWrite(ledPin_1_c, c);
digitalWrite(ledPin_1_b, b);
digitalWrite(ledPin_1_a, a);
// Turn on this anode.
digitalWrite(anodPin, HIGH);
// Delay
// NOTE: With the difference in Nixie bulbs you may have to change
// this delay to set the update speed of the bulbs. If you
// dont wait long enough the bulb will be dim or not light at all
// you want to set this delay just right so that you have
// nice bright output yet quick enough so that you can multiplex with
// more bulbs.
delay(2);
// Shut off this anode.
digitalWrite(anodPin, LOW);
}
////////////////////////////////////////////////////////////////////////
//
// DisplayNumberString
// Use: passing an array that is 8 elements long will display numbers
// on a 6 nixie bulb setup.
//
////////////////////////////////////////////////////////////////////////
void DisplayNumberString( int* array )
{
// bank 1 (bulb 0,3)
DisplayNumberSet(0,array[0],array[3]);
// bank 2 (bulb 1,4)
DisplayNumberSet(1,array[1],array[4]);
// bank 3 (bulb 2,5)
DisplayNumberSet(2,array[2],array[5]);
}
int NumberArray[6]={10,10,10,10,10,10};
const int MaxChars = 4;
char strValue[MaxChars+1];
int index = 0;
int stock_price = 0;
int d3, d2, d1, d0 = 0;
void loop()
{
if (Serial.available())
{
display.clearDisplay(); //clear I2C display
char ch = Serial.read(); //read char data from RPi via USB serial cable
if (ch > '9')
{
Serial.println("'A' received"); // received command to blank display
NumberArray[6]=(10,10,10,10,10,10); // '10' blanks a digit
DisplayNumberString(NumberArray);
delay(1000);
}
if (index < MaxChars && ch >= '0' && ch <= '9')
{
strValue[index++] = ch; //build 4-digit string
}
else
{
strValue[index] = 0;
stock_price=atoi(strValue); //convert ascii to integer
index = 0; //reset index for next time
// Serial.print("the stock price is "); //print to debug console
// Serial.println(stock_price);
d3 = stock_price % 10; // use modulo math to separate integer into indiv. digits
d2 = (stock_price / 10) % 10;
d1 = ((stock_price / 10) / 10) % 10;
d0 = (((stock_price / 10) / 10) / 10) % 10;
display.setCursor(0,18); // print stuff to OLED display (was used for debug)
display.println(stock_price);
display.display(); // this actually prints what was just set up to OLED
}
}
NumberArray[2] = d0; // print each digit to a tube (ordering depends on tube board)
NumberArray[3] = d1;
NumberArray[1] = d2;
NumberArray[5] = d3; // MSB
DisplayNumberString(NumberArray);
}