Pages: [1] 2
Author Topic: IN-17 Bulb CrossFade Code Example.  (Read 29804 times)
Emblazed
Administrator
Newbie
*****
Posts: 23


View Profile Email
« on: March 29, 2010, 08:20:33 AM »

[ Updated! ]
- The basic code base has been updated to support the new boards as well as bug fixes and clean up.

Here is an example of a one way to "cross fade" between the old value on a given bulb to the new or current value.

NOTE: Most of what is used is from the default clock code already post on the forums. But I will post the full source at the end.

This is an example of some of the tricks you can do with Multiplexing and using using delay changes to create a fade effect.

NOTE: This code works with IN-17 bulbs .. you may need to change some of the delays for other types of bulbs given that all are not the same. I have not tried this on my own.

Complete Example
Code:
// fading transitions sketch for 8-tube board with default connections.
// based on 6-tube sketch by Emblazed

// 09/03/2010 - Added Poxin's 12 hour setting for removing 00 from hours when set to 12 hour time
// 06/16/2011 - 4-tube-itized by Dave B.
// 08/19/2011 - modded for six bulb board, hours, minutes, seconds by Brad L.
// 01/28/2013 - expanded to 8 digit crossfade by Brad L.
// 12/04/2014 - First V2 standardization version by Brad L.
// 01/07/2015 - Code Revision by Jeremy Howa

// 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

#define _DEBUG          0
#define _bUSE_COLONS    0
#define _BULB_COUNT     6
#define _bUSE_CROSSFADE 0

#define _BrightnessLevelDelay     7.14//  100.0f / 14.0f

// 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
// NOTE: V1 board has this order flipped
int ledPin_a_1 = 10;
int ledPin_a_2 = 11;
int ledPin_a_3 = 12;
int ledPin_a_4 = 13;

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 )  SET HOURS
    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 )  SET MINUTES
    digitalWrite(15, HIGH); // set pin 15 as a pull up resistor.
 
    pinMode( 16, INPUT ); // set the virtual pin 16 (pin 1 on the analog inputs )  FREE TO USE AS INPUT OR OUTPUT
    digitalWrite(16, HIGH); // set pin 16 as a pull up resistor.

    pinMode( 17, INPUT ); // set the virtual pin 17 (pin 1 on the analog inputs )  FREE TO USE AS INPUT OR OUTPUT
    digitalWrite(17, HIGH); // set pin 17 as a pull up resistor.

    pinMode( 18, INPUT ); // set the virtual pin 18 (pin 1 on the analog inputs )  FREE TO USE AS INPUT OR OUTPUT
    digitalWrite(18, HIGH); // set pin 18 as a pull up resistor.

    pinMode( 19, INPUT ); // set the virtual pin 19 (pin 1 on the analog inputs )  FREE TO USE AS INPUT OR OUTPUT
    digitalWrite(19, HIGH); // set pin 19 as a pull up resistor. 
 
    // Open serial communications:
    if( _DEBUG )
        Serial.begin(9600);
}

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);
}

// Fade in/out times .. Values set for IN-17 Nixie Bulbs
float fadeMax    = 5.0f;   
float fadeStep   = 0.3f;   

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()
{
    if( _bUSE_COLONS == 1 )
    { 
        digitalWrite(ledPin_a_1, HIGH);
        SetSN74141Chips(0,0);   
        delay(1.8f); 
        SetSN74141Chips(1,1);   
        delay(1.8f); 
        SetSN74141Chips(2,2);   
        delay(1.8f); 
        SetSN74141Chips(3,3);   
        delay(1.8f); 
        digitalWrite(ledPin_a_1, LOW);   
    }
 
    if( _bUSE_CROSSFADE == 1 )
    {
        // 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);
    }
    else
    {
        // Anode channel 2 - numerals 1,5
        SetSN74141Chips(currNumberArray[1],currNumberArray[5]);   
        digitalWrite(ledPin_a_2, HIGH);   
            delay(_BrightnessLevelDelay);
        digitalWrite(ledPin_a_2, LOW);
 
        // Anode channel 3 - numerals 2,6
        SetSN74141Chips(currNumberArray[2],currNumberArray[6]);   
        digitalWrite(ledPin_a_3, HIGH);   
            delay(_BrightnessLevelDelay);
        digitalWrite(ledPin_a_3, LOW);
 
        // Anode channel 4 - numerals 3,7
        SetSN74141Chips(currNumberArray[3],currNumberArray[7]);   
        digitalWrite(ledPin_a_4, HIGH);   
            delay(_BrightnessLevelDelay);
        digitalWrite(ledPin_a_4, LOW);
    }
   
    if( _bUSE_CROSSFADE == 1 )
    { 
        // 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] = 0.0f;
                   NumberArrayFadeOutValue[i] = fadeMax; //affects the refresh cycle
                   currNumberArray[i] = NumberArray[i];
                }
            }   
        }
    }
    else
    {
        for( int i = 0 ; i < 8 ; i ++ )
        {
            currNumberArray[i] = NumberArray[i];
        }
    }   
}

// Defines
long SSECS = 10000;      // sub seconds
long SECS  = 1000;       // 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:32:10.  This is so we can count the correct order of tubes.
long clockHourSet = 01;
long clockMinSet  = 00;
long clockSecSet  = 00;
long clockSSecSet = 00;

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.
    // NOTE: Change this value from 1000 to a lower number to slow down the clock to debug.
    long time = (runTime) / 1000;
   
    // Set time based on offset..
    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 = 0;
   
    // 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 = sseconds - 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;
   
    // Slot four is used for dots .. should get them blinking ?? !!
    NumberArray[3] = lowerMins;
    NumberArray[2] = upperSeconds; 
    NumberArray[1] = lowerSeconds;

    DisplayFadeNumberString();   
}

Post Questions here..
- Emblazed
« Last Edit: March 25, 2015, 09:12:35 AM by Emblazed » Logged

poxin
Administrator
Newbie
*****
Posts: 11


View Profile
« Reply #1 on: March 31, 2010, 09:47:35 PM »

Been trying to get this to work with no luck. Using the code straight from here only lights up 2 bulbs and they flicker a lot.

I tried adding the code you changed to the old code and it pretty much does the same thing, not sure - I'm not a coder Smiley

In the original code I had, I needed to change two things to get my digits to work correctly:

Code:
// 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;

// anod pins
int ledPin_a_1 = 10;
int ledPin_a_2 = 11;
int ledPin_a_3 = 12;


and


Code:
 int NumberArray[6]={0,0,0,0,0,0};
  NumberArray[2] = upperHours;
  NumberArray[4] = lowerHours;
  NumberArray[0] = upperMins;
  NumberArray[5] = lowerMins;
  NumberArray[1] = upperSeconds;
  NumberArray[3] = lowerSeconds;
« Last Edit: April 01, 2010, 09:57:00 AM by poxin » Logged

Emblazed
Administrator
Newbie
*****
Posts: 23


View Profile Email
« Reply #2 on: August 20, 2010, 08:52:57 AM »

Poxin, Any update on this.. I'm back in the saddle and wanted to know if you have any updates on your build.

- Emblazed.
Logged

yellowthunder
Newbie
*
Posts: 2


View Profile
« Reply #3 on: June 15, 2011, 03:48:25 AM »

Newbie here who doesn't know a thing about coding,

This is great stuff!  I tried to plug in this script to the sample IN-17x4 script but only 2 numbers will show and will not cross fade.

Can anyone give me a clue?

BTW this project is great!  I got my Ardunix to work with the sample IN-17x4 script.  Lots of fun!

Thanks!
Logged

blave549
Newbie
*
Posts: 7


View Profile
« Reply #4 on: June 16, 2011, 01:28:22 PM »

The example fader sketch is for a 6-tube setup. Also, for whatever reason the pin declarations are different than the example 4-tube sketch provided in another thread that works for me. So I had to change the 0 through 10 pin numbers to 2 through 12 as noted by another post.

But the bigger problem is that the rest of the code is intended for 6 tubes, and quite a lot has to be modified to get it to work with a 4 tube setup. I have it working at least in terms of counting at the moment, but somehow I have managed to break the fading effect which is the whole point of the sketch!

I'll hopefully get it working and will report back with the modified source.

Dave B.
San Jose, CA
Logged

blave549
Newbie
*
Posts: 7


View Profile
« Reply #5 on: June 16, 2011, 02:37:43 PM »

OK here's my code. To be honest I'm not sure if the x-fade thing is working; if it is it's subtle.

This displays minutes and seconds; it's left as an exercise to change it to hours:minutes.

(note: I have not verified the hours/minutes set button functionality yet.)

cheers,

Dave.

Code:
// fading transitions sketch for 4-tube board with default connections.
// based on 6-tube sketch by Emblazed
// 4-tube-itized by Dave B. 16 June 2011
// this shows minutes and seconds only

// 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

int ledPin_0_a = 2;               
int ledPin_0_b = 3;
int ledPin_0_c = 4;
int ledPin_0_d = 5;

int ledPin_1_a = 6;               
int ledPin_1_b = 7;
int ledPin_1_c = 8;
int ledPin_1_d = 9;

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);     
 
  // NOTE:
  // Grounding on virtual pins 14 and 15 (analog pins 0 and 1) will set the Hour and Mins.
  pinMode( 14, INPUT ); // set the vertual pin 14 (pin 0 on the analog inputs )
  digitalWrite(14, HIGH); // set pin 14 as a pull up resistor.

  pinMode( 15, INPUT ); // set the vertual pin 15 (pin 1 on the analog inputs )
  digitalWrite(15, HIGH); // set pin 15 as a pull up resistor.
 
}

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);
}

////////////////////////////////////////////////////////////////////////
//
// DisplayNumberString
// Use: passing an array that is 4 elements long will display numbers
//      on a 4 nixie bulb setup.
//
////////////////////////////////////////////////////////////////////////
float fadeIn = 0.0f;
float fadeOut = 8.0f;
float fadeMax = 8.0f;
float fadeStep = 1.0f;
int NumberArray[4]={0,0,0,0};
int currNumberArray[4]={0,0,0,0};
float NumberArrayFadeInValue[4]={0.0f,0.0f,0.0f,0.0f};
float NumberArrayFadeOutValue[4]={8.0f,8.0f,8.0f,8.0f};

void DisplayFadeNumberString()
{
  // Nixie setup..
 
  // NOTE: If any of the bulbs need to blend then it will
  // be in time with the seconds bulbs. because any change only happens
  // on a one second interval.
 
  // 1 (0,3)
  SetSN74141Chips(currNumberArray[0],currNumberArray[3]);   
  digitalWrite(ledPin_a_1, HIGH);   
  delay(NumberArrayFadeOutValue[0]);
  SetSN74141Chips(NumberArray[0],NumberArray[3]);   
  delay(NumberArrayFadeInValue[0]);
  digitalWrite(ledPin_a_1, LOW);
 
  // 2 (1,2)
  SetSN74141Chips(currNumberArray[1],currNumberArray[2]);   
  digitalWrite(ledPin_a_2, HIGH);   
  delay(NumberArrayFadeOutValue[1]);
  SetSN74141Chips(NumberArray[1],NumberArray[2]);   
  delay(NumberArrayFadeInValue[1]);
  digitalWrite(ledPin_a_2, LOW);
 
  // Loop thru and update all the arrays, and fades.
  for( int i = 0 ; i < 4 ; i ++ )
  {
    if( NumberArray[i] != currNumberArray[i] )
    {
      NumberArrayFadeInValue[i] += fadeStep;
      NumberArrayFadeOutValue[i] -= fadeStep;
 
      if( NumberArrayFadeInValue[i] >= fadeMax )
      {
        NumberArrayFadeInValue[i] = 0.0f;
        NumberArrayFadeOutValue[i] = fadeMax;
        currNumberArray[i] = NumberArray[i];
      }
    }
  } 
}

// Defines
long MINS = 60;         // 60 Seconds in a Min.
long HOURS = 60 * MINS; // 60 Mins in an hour.
long DAYS = 24 * HOURS; // 24 Hours in a day. > Note: change the 24 to a 12 for non millitary time.

long runTime = 0;       // Time from when we started.

// default time sets. clock will start at 12:59:00
long clockHourSet = 12;
long clockMinSet  = 59;

int HourButtonPressed = false;
int MinButtonPressed = false;

////////////////////////////////////////////////////////////////////////
//
//
////////////////////////////////////////////////////////////////////////
void loop()     
{
  // Get milliseconds.
  runTime = 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;
 
  // Set time based on offset..
  // long hbump = 60*60*clockHourSet;
  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;

  // 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;
  if( upperSeconds >= 10 )   upperSeconds = upperSeconds / 10;
  if( upperMins >= 10 )      upperMins = upperMins / 10;
  if( upperHours >= 10 )     upperHours = upperHours / 10;

  // Fill in the Number array used to display on the tubes.
  NumberArray[3] = upperMins;
  NumberArray[2] = lowerMins;
  NumberArray[1] = upperSeconds;
  NumberArray[0] = lowerSeconds;

  // Display.
  DisplayFadeNumberString();
}
Logged

blave549
Newbie
*
Posts: 7


View Profile
« Reply #6 on: June 16, 2011, 04:06:36 PM »

OK it turns out that the fade is working in my code, but I had used the same value of fadeStep (1.0) that Emblazed has in the code I started with, which makes for a too-fast fade with my board. Changing it to 0.4 gives a nice fade without overdoing it (0.3 is too much, or should I say too little).

I suspect that this value has to be tweaked depending on how hard you're driving your IN-17s; I have my anode voltage set to about 150V which is about as low as I can go before digits start fading a bit.

have fun,

Dave.
Logged

nonentity
Co-Owner, Robotpirate
Administrator
Full Member
*****
Posts: 182



View Profile
« Reply #7 on: June 17, 2011, 08:59:53 AM »

OK it turns out that the fade is working in my code, but I had used the same value of fadeStep (1.0) that Emblazed has in the code I started with, which makes for a too-fast fade with my board. Changing it to 0.4 gives a nice fade without overdoing it (0.3 is too much, or should I say too little).

I suspect that this value has to be tweaked depending on how hard you're driving your IN-17s; I have my anode voltage set to about 150V which is about as low as I can go before digits start fading a bit.

have fun,

Dave.

WWooooohooo!  This is awesome code!  Thank you so much for posting this!  I have this on my personal unit on my desk at work and it's phenomenal!  Great job!
Logged

nonentity
Robotpirate Founder
www.robotpirate.com

yellowthunder
Newbie
*
Posts: 2


View Profile
« Reply #8 on: June 17, 2011, 07:11:30 PM »

Oh man, thanks!  I've been falling asleep trying to modify the code.  I can't wait to try it out!!!!!!
Logged

blave549
Newbie
*
Posts: 7


View Profile
« Reply #9 on: June 17, 2011, 08:06:01 PM »

Here is my code again but with some very slight tweaks - identical operation but with the  corrected fade value (I did end up using 0.3) and a few other cleanups that don't affect operation.



Code:
// fading transitions sketch for 4-tube board with default connections.
// based on 6-tube sketch by Emblazed
// 4-tube-itized by Dave Blevins 16 June 2011
// this shows minutes and seconds only

// 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

int ledPin_0_a = 2;               
int ledPin_0_b = 3;
int ledPin_0_c = 4;
int ledPin_0_d = 5;

int ledPin_1_a = 6;               
int ledPin_1_b = 7;
int ledPin_1_c = 8;
int ledPin_1_d = 9;

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);     
 
  // NOTE:
  // Grounding on virtual pins 14 and 15 (analog pins 0 and 1) will set the Hour and Mins.
  pinMode( 14, INPUT ); // set the vertual pin 14 (pin 0 on the analog inputs )
  digitalWrite(14, HIGH); // set pin 14 as a pull up resistor.

  pinMode( 15, INPUT ); // set the vertual pin 15 (pin 1 on the analog inputs )
  digitalWrite(15, HIGH); // set pin 15 as a pull up resistor.
 
}

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);
}

////////////////////////////////////////////////////////////////////////
//
// DisplayFadeNumberString
// Use: passing an array that is 4 elements long will display numbers
//      on a 4 nixie bulb setup.
//
////////////////////////////////////////////////////////////////////////
float fadeIn = 0.0;
float fadeOut = 8.0;
float fadeMax = 8.0;
float fadeStep = 0.3;  // tweak this to adjust speed of fade. Smaller number = slower fade
int NumberArray[4]={0,0,0,0};
int currNumberArray[4]={0,0,0,0};
float NumberArrayFadeInValue[4]={fadeIn,fadeIn,fadeIn,fadeIn};
float NumberArrayFadeOutValue[4]={fadeOut,fadeOut,fadeOut,fadeOut};

void DisplayFadeNumberString()
{
  // Nixie setup..
 
  // NOTE: If any of the bulbs need to blend then it will
  // be in time with the seconds bulbs. because any change only happens
  // on a one second interval.
 
  // 1 (0,3)
  SetSN74141Chips(currNumberArray[0],currNumberArray[3]);   
  digitalWrite(ledPin_a_1, HIGH);   
  delay(NumberArrayFadeOutValue[0]);
  SetSN74141Chips(NumberArray[0],NumberArray[3]);   
  delay(NumberArrayFadeInValue[0]);
  digitalWrite(ledPin_a_1, LOW);
 
  // 2 (1,2)
  SetSN74141Chips(currNumberArray[1],currNumberArray[2]);   
  digitalWrite(ledPin_a_2, HIGH);   
  delay(NumberArrayFadeOutValue[1]);
  SetSN74141Chips(NumberArray[1],NumberArray[2]);   
  delay(NumberArrayFadeInValue[1]);
  digitalWrite(ledPin_a_2, LOW);
 
  // Loop thru and update all the arrays, and fades.
  for( int i = 0 ; i < 4 ; i ++ )
  {
    if( NumberArray[i] != currNumberArray[i] )
    {
      NumberArrayFadeInValue[i] += fadeStep;
      NumberArrayFadeOutValue[i] -= fadeStep;
 
      if( NumberArrayFadeInValue[i] >= fadeMax )
      {
        NumberArrayFadeInValue[i] = 0.0f;
        NumberArrayFadeOutValue[i] = fadeMax;
        currNumberArray[i] = NumberArray[i];
      }
    }
  } 
}

// Defines
long MINS = 60;         // 60 Seconds in a Min.
long HOURS = 60 * MINS; // 60 Mins in an hour.
long DAYS = 24 * HOURS; // 24 Hours in a day. > Note: change the 24 to a 12 for non millitary time.

long runTime = 0;       // Time from when we started.

// default time sets. clock will start at 12:59:00
long clockHourSet = 12;
long clockMinSet  = 59;

int HourButtonPressed = false;
int MinButtonPressed = false;

////////////////////////////////////////////////////////////////////////
//
//
////////////////////////////////////////////////////////////////////////
void loop()     
{
  // Get milliseconds.
  runTime = 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;
 
  // Set time based on offset..
  // long hbump = 60*60*clockHourSet;
  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;

  // 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;
  if( upperSeconds >= 10 )   upperSeconds = upperSeconds / 10;
  if( upperMins >= 10 )      upperMins = upperMins / 10;
  if( upperHours >= 10 )     upperHours = upperHours / 10;

  // Fill in the Number array used to display on the tubes.
  NumberArray[3] = upperMins;
  NumberArray[2] = lowerMins;
  NumberArray[1] = upperSeconds;
  NumberArray[0] = lowerSeconds;

  // Display.
  DisplayFadeNumberString();
}
Logged

nonentity
Co-Owner, Robotpirate
Administrator
Full Member
*****
Posts: 182



View Profile
« Reply #10 on: June 17, 2011, 09:15:15 PM »

Again, excellent work, Blave!

I shot a vid this evening and posted it on the main site, giving you full credit for this latest code.  Big kudos!
Logged

nonentity
Robotpirate Founder
www.robotpirate.com

nonentity
Co-Owner, Robotpirate
Administrator
Full Member
*****
Posts: 182



View Profile
« Reply #11 on: August 18, 2011, 09:07:45 AM »

Testpost to see if forums are working...

Nothing to see here...
Logged

nonentity
Robotpirate Founder
www.robotpirate.com

poxin
Administrator
Newbie
*****
Posts: 11


View Profile
« Reply #12 on: August 24, 2011, 08:29:03 PM »

Been trying to adapt this into a six bulb setup. Here's what I have thus far (not working yet)

Code:
// fading transitions sketch for 4-tube board with default connections.
// based on 6-tube sketch by Emblazed
// 4-tube-itized by Dave Blevins 16 June 2011
// this shows minutes and seconds only

// 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

int ledPin_0_a = 2;               
int ledPin_0_b = 3;
int ledPin_0_c = 4;
int ledPin_0_d = 5;

int ledPin_1_a = 6;               
int ledPin_1_b = 7;
int ledPin_1_c = 8;
int ledPin_1_d = 9;

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);     
 
  // NOTE:
  // Grounding on virtual pins 14 and 15 (analog pins 0 and 1) will set the Hour and Mins.

  pinMode( 14, INPUT ); // set the vertual pin 14 (pin 0 on the analog inputs )
  digitalWrite(14, HIGH); // set pin 14 as a pull up resistor.

  pinMode( 15, INPUT ); // set the vertual pin 15 (pin 1 on the analog inputs )
  digitalWrite(15, HIGH); // set pin 15 as a pull up resistor.
 
}

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);
}

////////////////////////////////////////////////////////////////////////
//
// DisplayFadeNumberString

// Use: passing an array that is 4 elements long will display numbers
//      on a 4 nixie bulb setup.
//
////////////////////////////////////////////////////////////////////////
float fadeIn = 0.0;
float fadeOut = 8.0;
float fadeMax = 8.0;
float fadeStep = 0.3;  // tweak this to adjust speed of fade. Smaller number = slower fade
int NumberArray[4]={0,0,0,0};
int currNumberArray[6]={0,0,0,0,0,0};
float NumberArrayFadeInValue[6]={fadeIn,fadeIn,fadeIn,fadeIn,fadeIn,fadeIn};
float NumberArrayFadeOutValue[6]={fadeOut,fadeOut,fadeOut,fadeOut,fadeOut,fadeOut,};

void DisplayFadeNumberString()
{
  // Nixie setup..
 
  // NOTE: If any of the bulbs need to blend then it will
  // be in time with the seconds bulbs. because any change only happens
  // on a one second interval.
 
  // 1 (0,3)
  SetSN74141Chips(currNumberArray[0],currNumberArray[3]);   
  digitalWrite(ledPin_a_1, HIGH);   
  delay(NumberArrayFadeOutValue[0]);
  SetSN74141Chips(NumberArray[0],NumberArray[3]);   
  delay(NumberArrayFadeInValue[0]);
  digitalWrite(ledPin_a_1, LOW);
 
  // 2 (1,2)
  SetSN74141Chips(currNumberArray[1],currNumberArray[2]);   
  digitalWrite(ledPin_a_2, HIGH);   
  delay(NumberArrayFadeOutValue[1]);
  SetSN74141Chips(NumberArray[1],NumberArray[2]);   
  delay(NumberArrayFadeInValue[1]);
  digitalWrite(ledPin_a_2, LOW);

  // 3 (4,5)
  SetSN74141Chips(currNumberArray[4],currNumberArray[5]);   
  digitalWrite(ledPin_a_3, HIGH);   
  delay(NumberArrayFadeOutValue[1]);
  SetSN74141Chips(NumberArray[4],NumberArray[5]);   
  delay(NumberArrayFadeInValue[1]);
  digitalWrite(ledPin_a_3, LOW);
 
 
  // Loop thru and update all the arrays, and fades.
  for( int i = 0 ; i < 6 ; i ++ )
  {
    if( NumberArray[i] != currNumberArray[i] )
    {
      NumberArrayFadeInValue[i] += fadeStep;
      NumberArrayFadeOutValue[i] -= fadeStep;
 
      if( NumberArrayFadeInValue[i] >= fadeMax )
      {
        NumberArrayFadeInValue[i] = 0.0f;
        NumberArrayFadeOutValue[i] = fadeMax;
        currNumberArray[i] = NumberArray[i];

      }
    }
  } 
}

// Defines
long MINS = 60;         // 60 Seconds in a Min.
long HOURS = 60 * MINS; // 60 Mins in an hour.
long DAYS = 24 * HOURS; // 24 Hours in a day. > Note: change the 24 to a 12 for non millitary time.


long runTime = 0;       // Time from when we started.

// default time sets. clock will start at 12:59:00
long clockHourSet = 12;
long clockMinSet  = 59;


int HourButtonPressed = false;
int MinButtonPressed = false;

////////////////////////////////////////////////////////////////////////
//
//
////////////////////////////////////////////////////////////////////////
void loop()     
{
  // Get milliseconds.
  runTime = 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;
 
  // Set time based on offset..
  // long hbump = 60*60*clockHourSet;
  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;

  // 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;
  if( upperSeconds >= 10 )   upperSeconds = upperSeconds / 10;
  if( upperMins >= 10 )      upperMins = upperMins / 10;
  if( upperHours >= 10 )     upperHours = upperHours / 10;

  // Fill in the Number array used to display on the tubes.
  NumberArray[3] = upperMins;
  NumberArray[2] = lowerMins;
  NumberArray[1] = upperSeconds;
  NumberArray[0] = lowerSeconds;

  // Display.
  DisplayFadeNumberString();
}

Any help would be appreciated.
Logged

nonentity
Co-Owner, Robotpirate
Administrator
Full Member
*****
Posts: 182



View Profile
« Reply #13 on: August 25, 2011, 07:45:48 AM »

Hey Poxin, give this a shot.  It might not be perfect, but it's at least fading...

Code:
// fading transitions sketch for 4-tube board with default connections.
// based on 6-tube sketch by Emblazed
// 06/16/2011 - 4-tube-itized by Dave B.
//
// 08/19/2011 - modded for six bulb board, hours, minutes, seconds by Brad L.

// 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

int ledPin_0_a = 2;               
int ledPin_0_b = 3;
int ledPin_0_c = 4;
int ledPin_0_d = 5;

int ledPin_1_a = 6;               
int ledPin_1_b = 7;
int ledPin_1_c = 8;
int ledPin_1_d = 9;

int ledPin_a_1 = 10;
int ledPin_a_2 = 11;
int ledPin_a_3 = 12;
int ledPin_a_4 = 13;

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);     
 
  // NOTE:
  // Grounding on virtual pins 14 and 15 (analog pins 0 and 1) will set the Hour and Mins.
  pinMode( 14, INPUT ); // set the vertual pin 14 (pin 0 on the analog inputs )
  digitalWrite(14, HIGH); // set pin 14 as a pull up resistor.

  pinMode( 15, INPUT ); // set the vertual pin 15 (pin 1 on the analog inputs )
  digitalWrite(15, HIGH); // set pin 15 as a pull up resistor.
 
}

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);
}

////////////////////////////////////////////////////////////////////////
//
// DisplayNumberString
// Use: passing an array that is 4 elements long will display numbers
//      on a 4 nixie bulb setup.
//
////////////////////////////////////////////////////////////////////////
float fadeIn = 8.0f;
float fadeOut = 8.0f;
float fadeMax = 8.0f;
float fadeStep = 0.4f;
int NumberArray[6]={0,0,0,0,0,0};
int currNumberArray[6]={0,0,0,0,0,0};
float NumberArrayFadeInValue[6]={0.0f,0.0f,0.0f,0.0f,0.0f,0.0f};
float NumberArrayFadeOutValue[6]={8.0f,8.0f,8.0f,8.0f,8.0f,8.0f};

void DisplayFadeNumberString()
{
  // Nixie setup..
 
  // NOTE: If any of the bulbs need to blend then it will
  // be in time with the seconds bulbs. because any change only happens
  // on a one second interval.
 

 
  // Anode channel 1 - numerals 0,3
  SetSN74141Chips(currNumberArray[0],currNumberArray[3]);   
  digitalWrite(ledPin_a_1, HIGH);   
  delay(NumberArrayFadeOutValue[0]);
  SetSN74141Chips(NumberArray[0],NumberArray[3]);   
  delay(NumberArrayFadeInValue[0]);
  digitalWrite(ledPin_a_1, LOW);
 
  // Anode channel 2 - numerals 1,4
  SetSN74141Chips(currNumberArray[1],currNumberArray[4]);   
  digitalWrite(ledPin_a_2, HIGH);   
  delay(NumberArrayFadeOutValue[1]);
  SetSN74141Chips(NumberArray[1],NumberArray[4]);   
  delay(NumberArrayFadeInValue[1]);
  digitalWrite(ledPin_a_2, LOW);
 
   // Anode channel 3 - numerals 2,5
  SetSN74141Chips(currNumberArray[2],currNumberArray[5]);   
  digitalWrite(ledPin_a_3, HIGH);   
  delay(NumberArrayFadeOutValue[2]);
  SetSN74141Chips(NumberArray[2],NumberArray[5]);   
  delay(NumberArrayFadeInValue[2]);
  digitalWrite(ledPin_a_3, LOW);
 
  // Anode channel 4 - Unused on this board
  //SetSN74141Chips(currNumberArray[1],currNumberArray[0]);   
  //digitalWrite(ledPin_a_4, HIGH);   
  //delay(NumberArrayFadeOutValue[1]);
  //SetSN74141Chips(NumberArray[1],NumberArray[2]);   
  //delay(NumberArrayFadeInValue[1]);
  //digitalWrite(ledPin_a_4, LOW);
 
 
  // Loop thru and update all the arrays, and fades.
  for( int i = 0 ; i < 6 ; i ++ )
  {
    if( NumberArray[i] != currNumberArray[i] )
    {
      NumberArrayFadeInValue[i] += fadeStep;
      NumberArrayFadeOutValue[i] -= fadeStep;
 
      if( NumberArrayFadeInValue[i] >= fadeMax )
      {
        NumberArrayFadeInValue[i] = 0.0f;
        NumberArrayFadeOutValue[i] = fadeMax;
        currNumberArray[i] = NumberArray[i];
      }
    }
  } 
}

// Defines
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 millitary 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;

int HourButtonPressed = false;
int MinButtonPressed = false;

////////////////////////////////////////////////////////////////////////
//
//
////////////////////////////////////////////////////////////////////////
void loop()     
{
  // Get milliseconds.
  runTime = 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 time based on offset..
  // long hbump = 60*60*clockHourSet;
  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;

  // 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;
  if( upperSeconds >= 10 )   upperSeconds = upperSeconds / 10;
  if( upperMins >= 10 )      upperMins = upperMins / 10;
  if( upperHours >= 10 )     upperHours = upperHours / 10;

  // Fill in the Number array used to display on the tubes.
 
  NumberArray[3] = upperHours;
  NumberArray[1] = lowerHours;
  NumberArray[5] = upperMins;
  NumberArray[0] = lowerMins;
  NumberArray[4] = upperSeconds; 
  NumberArray[2] = lowerSeconds;

  // Display.
  DisplayFadeNumberString();
}
Logged

nonentity
Robotpirate Founder
www.robotpirate.com

poxin
Administrator
Newbie
*****
Posts: 11


View Profile
« Reply #14 on: August 25, 2011, 10:01:40 PM »

Thanks for the help, I see the issue now. Everything is working except for upperseconds is not fading for whatever reason.

Code:
// 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

int ledPin_0_a = 2;                
int ledPin_0_b = 3;
int ledPin_0_c = 4;
int ledPin_0_d = 5;

int ledPin_1_a = 6;                
int ledPin_1_b = 7;
int ledPin_1_c = 8;
int ledPin_1_d = 9;

int ledPin_a_1 = 10;
int ledPin_a_2 = 11;
int ledPin_a_3 = 12;
int ledPin_a_4 = 13;

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);    
 
  // NOTE:
  // Grounding on virtual pins 14 and 15 (analog pins 0 and 1) will set the Hour and Mins.
  pinMode( 14, INPUT ); // set the vertual pin 14 (pin 0 on the analog inputs )
  digitalWrite(14, HIGH); // set pin 14 as a pull up resistor.

  pinMode( 15, INPUT ); // set the vertual pin 15 (pin 1 on the analog inputs )
  digitalWrite(15, HIGH); // set pin 15 as a pull up resistor.
 
}

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 fadeIn = 8.0f;
float fadeOut = 8.0f;
float fadeMax = 8.0f;
float fadeStep = 0.4f;
int NumberArray[6]={0,0,0,0,0,0};
int currNumberArray[6]={0,0,0,0,0,0};
float NumberArrayFadeInValue[6]={0.0f,0.0f,0.0f,0.0f,0.0f,0.0f};
float NumberArrayFadeOutValue[6]={8.0f,8.0f,8.0f,8.0f,8.0f,8.0f};

void DisplayFadeNumberString()
{
 
  // Anode channel 1 - numerals 0,3
  SetSN74141Chips(currNumberArray[0],currNumberArray[3]);  
  digitalWrite(ledPin_a_1, HIGH);  
  delay(NumberArrayFadeOutValue[0]);
  SetSN74141Chips(NumberArray[0],NumberArray[3]);  
  delay(NumberArrayFadeInValue[0]);
  digitalWrite(ledPin_a_1, LOW);
  
  // Anode channel 2 - numerals 1,4
  SetSN74141Chips(currNumberArray[1],currNumberArray[4]);  
  digitalWrite(ledPin_a_2, HIGH);  
  delay(NumberArrayFadeOutValue[1]);
  SetSN74141Chips(NumberArray[1],NumberArray[4]);  
  delay(NumberArrayFadeInValue[1]);
  digitalWrite(ledPin_a_2, LOW);
  
   // Anode channel 3 - numerals 2,5
  SetSN74141Chips(currNumberArray[2],currNumberArray[5]);  
  digitalWrite(ledPin_a_3, HIGH);  
  delay(NumberArrayFadeOutValue[2]);
  SetSN74141Chips(NumberArray[2],NumberArray[5]);  
  delay(NumberArrayFadeInValue[2]);
  digitalWrite(ledPin_a_3, LOW);
  
  // Loop thru and update all the arrays, and fades.
  for( int i = 0 ; i < 6 ; i ++ )
  {
    if( NumberArray[i] != currNumberArray[i] )
    {
      NumberArrayFadeInValue[i] += fadeStep;
      NumberArrayFadeOutValue[i] -= fadeStep;
  
      if( NumberArrayFadeInValue[i] >= fadeMax )
      {
        NumberArrayFadeInValue[i] = 0.0f;
        NumberArrayFadeOutValue[i] = fadeMax;
        currNumberArray[i] = NumberArray[i];
      }
    }
  }  
}

// Defines
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 millitary 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;

int HourButtonPressed = false;
int MinButtonPressed = false;

////////////////////////////////////////////////////////////////////////
//
//
////////////////////////////////////////////////////////////////////////
void loop()    
{
  // Get milliseconds.
  runTime = 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 time based on offset..
  // long hbump = 60*60*clockHourSet;
  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;

  // 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;
  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[5] = upperHours;
  NumberArray[1] = lowerHours;
  NumberArray[3] = upperMins;
  NumberArray[2] = lowerMins;
  NumberArray[4] = upperSeconds;  
  NumberArray[0] = lowerSeconds;

  // Display.
  DisplayFadeNumberString();
}

The only other thing I changed was if the clock is displaying 0 0 for the hours, I want it to say 12.

Code:
 if( upperHours == 0 && lowerHours == 0 )
  {
    upperHours = 1;
    lowerHours = 2;
  }

This seems to work fine.

Images: http://imgur.com/a/c79QS
Video: http://www.youtube.com/watch?v=lG1PW85CdcQ
« Last Edit: August 25, 2011, 10:52:22 PM by poxin » Logged

Pages: [1] 2
Print
Jump to: