Pages: [1]
Author Topic: ArduiNIX V2 Base Code  (Read 2486 times)
nonentity
Co-Owner, Robotpirate
Administrator
Full Member
*****
Posts: 181



View Profile
« on: December 10, 2014, 08:47:48 pm »

Hi All,

Below I have placed the base code for the ArduiNIX V2.  Please let me know how it works, and feel free to change or improve it.

Thanks!

Code:
// fading transitions sketch for 8-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.
// 09/03/2010 - Added Poxin's 12 hour setting for removing 00 from hours when set to 12 hour time
// 01/28/2013 - expanded to 8 digit crossfade by Brad L.
// 12/04/2014 - First V2 standardization version 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

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

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

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

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

  pinMode( 19, INPUT ); // set the virtual pin 15 (pin 1 on the analog inputs )  FREE TO USE AS INPUT OR OUTPUT
  digitalWrite(19, HIGH); // set pin 15 as a pull up resistor. 
 
 // Open serial communications:
 // 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);
}


float fadeIn = 4.0f;
float fadeOut = 4.0f;
float fadeMax = 6.0f;
float fadeStep = 1.0f;

//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]);  THIS LIGHTS THE INS-1 COLONS
 
  digitalWrite(ledPin_a_1, HIGH);
  SetSN74141Chips(0,0);   
delay(1.0f); 
  SetSN74141Chips(1,1);   
delay(1.0f); 
 // SetSN74141Chips(2,2);
//delay(1.0f);
//  SetSN74141Chips(3,3);
//delay(1.0f); 
//  SetSN74141Chips(4,4);   
//delay(1.0f); 
  SetSN74141Chips(5,5);   
delay(1.0f); 
  SetSN74141Chips(6,6);
delay(1.0f);
  SetSN74141Chips(7,7);
delay(1.0f);
  SetSN74141Chips(8,8);   
delay(1.0f); 
  SetSN74141Chips(9,9);
delay(1.0f);
  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] = 0.0f;
        NumberArrayFadeOutValue[i] = fadeMax; //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  = 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.
  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 = 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;
  NumberArray[3] = lowerMins;
  NumberArray[2] = upperSeconds; 
  NumberArray[1] = lowerSeconds;
 
  DisplayFadeNumberString();
}
Logged

nonentity
Robotpirate Founder
www.robotpirate.com

netflow
Newbie
*
Posts: 5


View Profile Email
« Reply #1 on: February 24, 2015, 03:35:15 pm »

Is it okay to use this code with a V1 board?  When comparing this and the original code I see the input pins are the same, but there are a few things in here I don't understand and wanted to make sure.
Logged

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



View Profile
« Reply #2 on: February 28, 2015, 10:30:04 pm »

Is it okay to use this code with a V1 board?  When comparing this and the original code I see the input pins are the same, but there are a few things in here I don't understand and wanted to make sure.

Yes, but you might have to flip the anode connections.  A1 to A4, etc.
Logged

nonentity
Robotpirate Founder
www.robotpirate.com

Pages: [1]
Print
Jump to: