# Question on Driving a nixie via 74141 via Teensy 2.0++

This is may be pretty simple, but i am unable to get the desired effect. How it’s “supposed” to work. When a key is pressed (adafruit Membrane 3x4 Matrix Keypad) it will cycle through 16 times. On the 15 time it should stop at a point according to the digit stored in “holder”. What happens is, it cycles though 16 times and defaults back to zero (0 is all four control lines low). Everything works correctly, except I can’t get it to stop on the right digit.

Any ideas?

P.S. yes, the code is inefficient (to say the least) but is done so purposely to help with initial debugging.

Thanks.

``````#include <Keypad.h>
int a = 14;
int b = 15;
int c = 16;
int d = 17;
int holder;
int count = 0;
int hold;
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
{
'1','2','3'    }
,
{
'4','5','6'    }
,
{
'7','8','9'    }
,
{
'*','0','#'    }
};
byte rowPins[ROWS] = {
39, 40, 41, 42}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {
43, 44, 45}; //connect to the column pinouts of the keypad

void setup(){
Serial.begin(9600);
pinMode(a, OUTPUT);
pinMode(b, OUTPUT);
pinMode(c, OUTPUT);
pinMode(d, OUTPUT);

}

void loop(){

if (key){
Serial.println(key); //wait for keypress from 9 digit pad
key = holder; // grab the digit, and after 15 cycles stop on that digit
count = 0;
do{  //cycle through all digits via 74141 to nixie
zero();
if(holder == 0 && count ==15){
delay(50000);
}
one();
if(holder == 1 && count ==15){
delay(50000);
}
two();
if(holder == 2 && count ==15){
delay(50000);
}
three();
if(holder == 3 && count ==15){
delay(50000);
}
four();
if(holder == 4 && count ==15){
delay(50000);
}
five();
if(holder == 5 && count ==15){
delay(50000);
}
six();
if(holder == 6 && count ==15){
delay(50000);
}
seven();
if(holder == 7 && count ==15){
delay(50000);
}
eight();
if(holder == 8 && count ==15){
delay(50000);
}
nine();
if(holder == 9 && count ==15){
delay(50000);
}
if(count == 15){
key = holder;
}
count = count + 1;
Serial.println(count);
}
while (count < 16); // cycle though 15 times till

//;'  delay(10000);

//   cycle();

}
}
void zero(){
digitalWrite(a, LOW);  // nixie digit 0
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, LOW);
delay(50);
}
void one(){
digitalWrite(a, HIGH);  //nixie digit 1
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, LOW);
delay(50);
}
void two(){
digitalWrite(a, LOW);  //nixie digit 2
digitalWrite(b, HIGH);
digitalWrite(c, LOW);
digitalWrite(d, LOW);
delay(50);
}
void three(){
digitalWrite(a, HIGH);    //nixie digit 3
digitalWrite(b, HIGH);
digitalWrite(c, LOW);
digitalWrite(d, LOW);
delay(50);
}
void four(){
digitalWrite(a, LOW);    //nixie digit 4
digitalWrite(b, LOW);
digitalWrite(c, HIGH);
digitalWrite(d, LOW);
delay(50);
}
void five(){
digitalWrite(a, HIGH);    //nixie digit 5
digitalWrite(b, LOW);
digitalWrite(c, HIGH);
digitalWrite(d, LOW);
delay(50);
}
void six(){
digitalWrite(a, LOW);    //nixie digit 6
digitalWrite(b, HIGH);
digitalWrite(c, HIGH);
digitalWrite(d, LOW);
delay(50);
}
void seven(){
digitalWrite(a, HIGH);    //nixie digit 7
digitalWrite(b, HIGH);
digitalWrite(c, HIGH);
digitalWrite(d, LOW);
delay(50);
}
void eight(){
digitalWrite(a, LOW);   //nixie digit 8
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, HIGH);
delay(50);
}
void nine(){
digitalWrite(a, HIGH);   //nixie digit 9
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, HIGH);
delay(50);
}
``````

Where is "holder" ever assigned a value ?

In the initial 'if' statement "key = holder; // grab the digit, and after 15 cycles stop on that digit" Should it be some place else, or is it incorrect?

holder = key

Thanks for the help, :) I knew it was something simple.