Pages: [1]
Author Topic: Six Bulb Code Example.  (Read 16894 times)
Emblazed
Administrator
Newbie
*****
Posts: 23


View Profile Email
« on: June 22, 2009, 09:58:33 AM »

This is some example code for running 6 IN-17 Bulbs with the ArduiNIX. The following can also be used to run any other type of bulbs but will need to have some of the timing changed to support other bulbs refresh delays.

Just drop this code into a new Arduino project and your ready.

Code:
//
// Arduinix 6 Bulb ( IN-17 )
// - Also supports Hour and Min. time set.
//
// This code runs a six bulb setup and displays a prototype clock setup.
// NOTE: the delay is setup for IN-17 nixie bulbs.
//
// by Jeremy Howa
// www.robotpirate.com
// www.arduinix.com
// 2008 - 2009
//
// Last Edit Aug 29, 2009
//

// SN74141 : True 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_ON   false

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

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 pints 14 and 15 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.
  
  if( DEBUG_ON )
  {
    Serial.begin(9600);
  }
}

////////////////////////////////////////////////////////////////////////
//
// DisplayNumberSet
// Use: Passing anod number, and number for bulb 1 and bulb 2, this function
//      looks up the truth table and opens the correct outs from the arduino
//      to light the numbers given to this funciton (num1,num2).
//      On a 6 nixie bulb setup.
//
////////////////////////////////////////////////////////////////////////
void DisplayNumberSet( int anod, int num1, int num2 )
{
  int anodPin;
  int a,b,c,d;
  
  // set defaults.
  a=0;b=0;c=0;d=0; // will display a zero.
  anodPin =  ledPin_a_1;     // default on first anod.
  
  // 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;
  }  
  
  // 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;
  }
  
  // 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 anod.
  digitalWrite(anodPin, HIGH);  

  // Delay
  // NOTE: With the differnce 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 anod.
  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]);  
}

// 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
// NOTE: We start seconds at 0 so we dont need a clock set
//       The values you see here would be what you change
//       if you added a set clock inputs to the board.
long clockHourSet = 12;
long clockMinSet  = 59;

int HourButtonPressed = false;
int MinButtonPressed = false;

////////////////////////////////////////////////////////////////////////
//
//
////////////////////////////////////////////////////////////////////////
void loop()    
{
  // Get milliseconds.
  runTime = millis();

  // Get time in seconds.
  long time = (runTime) / 1000;
  
  int hourInput = digitalRead(14);  
  int minInput  = digitalRead(15);
  
  if( DEBUG_ON )
    Serial.println( hourInput );      
  
  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;
  }
  
  // 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;

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

  // Display.
  DisplayNumberString( NumberArray );
}


Jeremy Howa aka: Emblazed
ArduiNIX Coder
RobotPirate
« Last Edit: September 18, 2009, 08:18:49 AM by Emblazed » Logged

miu
Newbie
*
Posts: 7


View Profile
« Reply #1 on: September 04, 2009, 06:02:07 PM »

I am using this example to do multiplexing. But I found that Anode 3 (i.e. ledPin_a_2 engaged to pin 11 of Arduino) is not working, while all other 3 anodes work just fine. Anode 3 is always HIGH (180V) and is not responsive to the change of delay time.

Does anyone have the same problem and is there a solution?

THX!
Logged

Masoste
Newbie
*
Posts: 10



View Profile
« Reply #2 on: September 24, 2009, 12:45:49 AM »

It seems to be working for me.
It's great to have a nice simple time setting function using the analog input.
Thanks.

Now if I could also get a count up timer function then I'd be set.
I'm trying to replace a timer that counts up, holds and resets. Plus I'd like to be able to switch back and forth between the timer and a clock...
Anyone using the arduinix for a timer?
Logged

Emblazed
Administrator
Newbie
*****
Posts: 23


View Profile Email
« Reply #3 on: September 28, 2009, 09:38:45 AM »

I am using this example to do multiplexing. But I found that Anode 3 (i.e. ledPin_a_2 engaged to pin 11 of Arduino) is not working, while all other 3 anodes work just fine. Anode 3 is always HIGH (180V) and is not responsive to the change of delay time.

Does anyone have the same problem and is there a solution?

THX!

@ miu
Now that your kit is working.. does this code work for you know?
Logged

Emblazed
Administrator
Newbie
*****
Posts: 23


View Profile Email
« Reply #4 on: September 28, 2009, 09:40:58 AM »

It seems to be working for me.
It's great to have a nice simple time setting function using the analog input.
Thanks.

Now if I could also get a count up timer function then I'd be set.
I'm trying to replace a timer that counts up, holds and resets. Plus I'd like to be able to switch back and forth between the timer and a clock...
Anyone using the arduinix for a timer?

@Masoste
I'm sure I could create a timer setup for you.. As soon as I get some cycles I will try and do this and post it up for ya.

-Emblazed
Logged

Masoste
Newbie
*
Posts: 10



View Profile
« Reply #5 on: October 22, 2009, 11:35:39 AM »

So what modifications would I have to make to be able to drive a pair of decimals?

I'm guessing that I'd have to set up the fourth anode which would be int ledPin_a_4 = 13; but I'm kind of at a loss beyond that.
Logged

Emblazed
Administrator
Newbie
*****
Posts: 23


View Profile Email
« Reply #6 on: October 22, 2009, 04:19:34 PM »

yep.. drive them off the forth pipe and then turn them on and off ever other second.

.. Emblazed
Logged

Masoste
Newbie
*
Posts: 10



View Profile
« Reply #7 on: October 24, 2009, 06:37:17 PM »

Thanks Emblazened,
Um, but  I'm afraid I don't know how to do that. And actually I don't even want them to flash.
Sorry, I'm pretty new to all this. In fact I'm kind of surprised that I got as far as I have pimply simply using the code that you wrote.

I get that I need to declare the variable of of the fourth anode:
Code:
int ledPin_a_4 = 13

...and I assume determine that that anode will be firing along with all the others:

Code:
case 3:    anodPin =  ledPin_a_4;    break;

But then where and how do I say to turn a cathode on the fourth anode? I'm guessing that I can still do this in the setup if don't want the decimal to blink.
« Last Edit: October 26, 2009, 08:12:14 PM by Masoste » Logged

Secret Chimp
Newbie
*
Posts: 1


View Profile
« Reply #8 on: December 23, 2009, 01:20:20 AM »

Hi Guys.  

I've built a few nixie clocks but I'm new to the programming side of this sort of project.  I'm hoping you guys could help me understand the example code above.  

Is the code set up for A1 to be wired to nixie digits 1 and 4, A2 goes to digits 2 and 5, and A3 goes to digits 3 and 6?  

Or

Is it set up so that A1 fires tubes 1 and 2, A2 fires 3 and 4, and A3 fires 5 and 6?

***update...figured it out... A1 = 0-3, A2 = 1-4, A3 = 2-5***



About setting the time, the text in the code refers to pins 0 and 1 to be grounded (I'm hoping to use a button).  What is a good source of ground?  Can I use either of the two GND pins on the shield or is there a better place to ground?

Thanks!

Ralph
« Last Edit: December 23, 2009, 01:30:08 AM by Secret Chimp » Logged

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



View Profile
« Reply #9 on: December 23, 2009, 08:39:55 AM »

Hi Guys.  

I've built a few nixie clocks but I'm new to the programming side of this sort of project.  I'm hoping you guys could help me understand the example code above.  

Is the code set up for A1 to be wired to nixie digits 1 and 4, A2 goes to digits 2 and 5, and A3 goes to digits 3 and 6?  

Or

Is it set up so that A1 fires tubes 1 and 2, A2 fires 3 and 4, and A3 fires 5 and 6?

***update...figured it out... A1 = 0-3, A2 = 1-4, A3 = 2-5***



About setting the time, the text in the code refers to pins 0 and 1 to be grounded (I'm hoping to use a button).  What is a good source of ground?  Can I use either of the two GND pins on the shield or is there a better place to ground?

Thanks!

Ralph

Yes, you can use either of the GND pins on the shield for that.

Hope you enjoy your kit!

Let us know if you need anything else!

Brad

Logged

nonentity
Robotpirate Founder
www.robotpirate.com

slyly
Newbie
*
Posts: 2


View Profile
« Reply #10 on: January 03, 2010, 01:45:27 PM »

Just chiming in to remind everyone that setting all four pins of the SN74141 to high will blank a digit.

I'd post what I did for a 4 digit 12 hour clock if my code wasn't some scary hacked up Frankenstein...  unless you really want to be more confused than ever.
Logged

Pages: [1]
Print
Jump to: