Skip to content

Instantly share code, notes, and snippets.

@D2theR
Created January 31, 2021 21:39
Show Gist options
  • Save D2theR/57e7c004be7c94b65d2f9a0a18eb2c72 to your computer and use it in GitHub Desktop.
Save D2theR/57e7c004be7c94b65d2f9a0a18eb2c72 to your computer and use it in GitHub Desktop.
This is Arduino UNO Arduinix Nixie Tube drive code that also attempts to drive some NeoPixel Flora v2.
// This code was taken and modified from http://www.arduinix.com/Main/Code/ANX_IN-17x8_v1.0.txt
// Fading transitions sketch for 8-tube board with default connections.
// based on 6-tube sketch by Emblazed
// 01/28/2013 - expanded to 8 digit crossfade by Brad L.
// 06/16/2011 - 4-tube-itized by Dave B.
//
// 08/19/2011 - modded for six bulb board, hours, minutes, seconds by Brad L.
//
// 09/03/2010 - Added Poxin's 12 hour setting for removing 00 from hours when set to 12 hour time
//
// 01/31/2021 - Attempted to add NeoPixel Flora v2 LEDS. See https://www.adafruit.com/product/1260
// SN74141 : Truth Table
//D C B A #
//L,L,L,L 0
//L,L,L,H 1
//L,L,H,L 2
//L,L,H,H 3
//L,H,L,L 4
//L,H,L,H 5
//L,H,H,L 6
//L,H,H,H 7
//H,L,L,L 8
//H,L,L,H 9
// 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;
int ledPin_a_4 = 13;
// NeoPixel LED Library
#include <Adafruit_NeoPixel.h>
// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
#define PIN 16 // Analog pin A2
Adafruit_NeoPixel strip = Adafruit_NeoPixel(2, PIN, NEO_GRB + NEO_KHZ800);
// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
// and minimize distance between Arduino and first pixel. Avoid connecting
// on a live circuit...if you must, connect GND first.
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);
pinMode(ledPin_a_4, OUTPUT);
// NOTE: Grounding on virtual pins 14 and 15 (analog pins 0 and 1) will set the Hour and Mins.
pinMode( 14, INPUT ); // set the virtual pin 14 (pin 0 on the analog inputs )
digitalWrite(14, HIGH); // set pin 14 as a pull up resistor.
pinMode( 15, INPUT ); // set the virtual pin 15 (pin 1 on the analog inputs )
digitalWrite(15, HIGH); // set pin 15 as a pull up resistor.
// Open serial communications:
Serial.begin(9600);
// Initialize LEDs
strip.begin();
strip.setBrightness(100);
strip.show(); // Initialize all pixels to 'off'
}
void SetSN74141Chips( int num2, int num1 )
{
int a,b,c,d;
// set defaults.
a=0;b=0;c=0;d=0; // will display a zero.
// 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;
default: a=1;b=1;c=1;d=1;
break;
}
// 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;
default: a=1;b=1;c=1;d=1;
break;
}
// Write to output pins
digitalWrite(ledPin_1_d, d);
digitalWrite(ledPin_1_c, c);
digitalWrite(ledPin_1_b, b);
digitalWrite(ledPin_1_a, a);
}
float fadeMax = 0.1f;
float fadeStep = 0.1f;
int NumberArray[8]={0,0,0,0,0,0,0,0};
int currNumberArray[8]={0,0,0,0,0,0,0,0};
float NumberArrayFadeInValue[8]={0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f};
float NumberArrayFadeOutValue[8]={5.0f,5.0f,5.0f,5.0f,5.0f,5.0f,5.0f,5.0f};
void DisplayFadeNumberString()
{
// Anode channel 1 - numerals 0,4
SetSN74141Chips(currNumberArray[0],currNumberArray[4]);
digitalWrite(ledPin_a_1, HIGH);
delay(NumberArrayFadeOutValue[0]);
SetSN74141Chips(NumberArray[0],NumberArray[4]);
delay(NumberArrayFadeInValue[0]);
digitalWrite(ledPin_a_1, LOW);
// Anode channel 2 - numerals 1,5
SetSN74141Chips(currNumberArray[1],currNumberArray[5]);
digitalWrite(ledPin_a_2, HIGH);
delay(NumberArrayFadeOutValue[1]);
SetSN74141Chips(NumberArray[1],NumberArray[5]);
delay(NumberArrayFadeInValue[1]);
digitalWrite(ledPin_a_2, LOW);
// Anode channel 3 - numerals 2,6
SetSN74141Chips(currNumberArray[2],currNumberArray[6]);
digitalWrite(ledPin_a_3, HIGH);
delay(NumberArrayFadeOutValue[2]);
SetSN74141Chips(NumberArray[2],NumberArray[6]);
delay(NumberArrayFadeInValue[2]);
digitalWrite(ledPin_a_3, LOW);
// Anode channel 4 - numerals 3,7
SetSN74141Chips(currNumberArray[3],currNumberArray[7]);
digitalWrite(ledPin_a_4, HIGH);
delay(NumberArrayFadeOutValue[3]);
SetSN74141Chips(NumberArray[3],NumberArray[7]);
delay(NumberArrayFadeInValue[3]);
digitalWrite(ledPin_a_4, LOW);
// Loop thru and update all the arrays, and fades.
for( int i = 0 ; i < 8 ; i ++ ) //equal to & of digits
{
if( NumberArray[i] != currNumberArray[i] )
{
NumberArrayFadeInValue[i] += fadeStep;
NumberArrayFadeOutValue[i] -= fadeStep;
if( NumberArrayFadeInValue[i] >= fadeMax )
{
NumberArrayFadeInValue[i] = 2.0f;
NumberArrayFadeOutValue[i] = 4.0f; //affects the refresh cycle
currNumberArray[i] = NumberArray[i];
}
}
}
}
// Defines
long SSECS = 100; // sub seconds
long SECS = 60; // milliseconds in a Sec
long MINS = 60; // 60 Seconds in a Min.
long HOURS = 60 * MINS; // 60 Mins in an hour.
long DAYS = 12 * HOURS; // 24 Hours in a day. > Note: change the 24 to a 12 for non military time.
long runTime = 0; // Time from when we started.
// default time sets. clock will start at 12:34:00. This is so we can count the correct order of tubes.
long clockHourSet = 12;
long clockMinSet = 34;
long clockSecSet = 56;
long clockSSecSet = 12;
int HourButtonPressed = false;
int MinButtonPressed = false;
////////////////////////////////////////////////////////////////////////
//
//
////////////////////////////////////////////////////////////////////////
void loop()
{
// Get milliseconds.
runTime = millis();
//int ssTime = millis();
int hourInput = digitalRead(14);
int minInput = digitalRead(15);
if( hourInput == 0 )
HourButtonPressed = true;
if( minInput == 0 )
MinButtonPressed = true;
if( HourButtonPressed == true && hourInput == 1 )
{
clockHourSet++;
HourButtonPressed = false;
}
if( MinButtonPressed == true && minInput == 1 )
{
clockMinSet++;
MinButtonPressed = false;
}
// Get time in seconds.
long time = (runTime) / 1000; //////////change this value to speed up or slow down the clock, set to smaller number such as 10, 1, or 100 for debugging
int sstime = (runTime) / 10;
// Set time based on offset..
// long hbump = 60*60*clockHourSet;
//long sbump = 60*60*60*clockHourSet; //change hourset to secondset
long hbump = 60*60*clockHourSet;
long mbump = 60*clockMinSet;
time += mbump + hbump;
// Convert time to days,hours,mins,seconds
long days = time / DAYS; time -= days * DAYS;
long hours = time / HOURS; time -= hours * HOURS;
long minutes = time / MINS; time -= minutes * MINS;
long seconds = time;
// long sseconds = 76;// time -= seconds * SECS;
long sseconds = runTime / SECS; time -= sseconds * SECS;
// Get the high and low order values for hours,min,seconds.
int lowerHours = hours % 10;
int upperHours = hours - lowerHours;
int lowerMins = minutes % 10;
int upperMins = minutes - lowerMins;
int lowerSeconds = seconds % 10;
int upperSeconds = seconds - lowerSeconds;
int lowerSSeconds = sseconds % 10;
int upperSSeconds = lowerSSeconds % 10; upperSSeconds = upperSSeconds /10;//- lowerSSeconds;
if( upperSSeconds >= 10 ) upperSSeconds = upperSSeconds / 10;
if( upperSeconds >= 10 ) upperSeconds = upperSeconds / 10;
if( upperMins >= 10 ) upperMins = upperMins / 10;
if( upperHours >= 10 ) upperHours = upperHours / 10;
if( upperHours == 0 && lowerHours == 0 )
{
upperHours = 1;
lowerHours = 2;
}
// Fill in the Number array used to display on the tubes.
NumberArray[7] = upperHours;
NumberArray[6] = lowerHours;
NumberArray[5] = upperMins;
NumberArray[4] = lowerMins;
NumberArray[3] = upperSeconds;
NumberArray[2] = lowerSeconds;
NumberArray[1] = lowerSSeconds; //upperSSeconds;
NumberArray[0] = lowerSSeconds; //lowerSSeconds;
Serial.print(lowerSSeconds);
Serial.println();
// Display.
//DisplayFadeNumberString();
// Display.
DisplayFadeNumberString();
rainbow(20);
rainbowCycle(20);
}
void rainbow(uint8_t wait) {
uint16_t i, j;
for(j=0; j<256; j++) {
for(i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel((i+j) & 255));
}
strip.show();
delay(wait);
}
}
// Slightly different, this makes the rainbow equally distributed throughout
void rainbowCycle(uint8_t wait) {
uint16_t i, j;
for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
for(i=0; i< strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
}
strip.show();
delay(wait);
}
}
// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
WheelPos = 255 - WheelPos;
if(WheelPos < 85) {
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
}
if(WheelPos < 170) {
WheelPos -= 85;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
WheelPos -= 170;
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment