Driving Nixie tube using button

Like in topic, I'm trying to drive Nixie tube using button (and K155ID1 driver). I want to make it display each of numbers consecutively and change it only when it detects that button was pushed. I don't know how to make state change detection so I'm stuck with infinte counting loop. Here's code.

int Counter = 0;
#define A 12
#define B 11
#define C 10
#define D 9
void setup() {
  Serial.begin(9600);
  pinMode(8, OUTPUT);
  pinMode(D, OUTPUT);// D
  pinMode(C, OUTPUT);// C
  pinMode(B, OUTPUT);// B
  pinMode(A, OUTPUT);// A
  digitalWrite(8, LOW);
}
void loop() {
 digitalWrite(8, HIGH);
 Counter = Counter +1;
 delay(1000);
 Serial.print(Licznik);
 //0 
 if (Counter == 0){
 digitalWrite(D, LOW);  //D
 digitalWrite(C, LOW);  //C
 digitalWrite(B, LOW);  //B
 digitalWrite(A, LOW);  //A
 }
 //1
  if (Counter == 1){
 digitalWrite(D, LOW);  //D
 digitalWrite(C, LOW);  //C
 digitalWrite(B, LOW);  //B
 digitalWrite(A, HIGH); //A
 }
 //2
 if (Counter == 2){
 digitalWrite(D, LOW);  //D
 digitalWrite(C, LOW);  //C
 digitalWrite(B, HIGH); //B
 digitalWrite(A, LOW);  //A
 }
 //3
 if (Counter == 3){
 digitalWrite(D, LOW);  //D
 digitalWrite(C, LOW);  //C
 digitalWrite(B, HIGH); //B
 digitalWrite(A, HIGH); //A
 }
 //4
 if (Counter == 4){
 digitalWrite(D, LOW);  //D
 digitalWrite(C, HIGH); //C
 digitalWrite(B, LOW);  //B
 digitalWrite(A, LOW);  //A
 }
 //5
 if (Counter == 5){
 digitalWrite(D, LOW);  //D
 digitalWrite(C, HIGH); //C
 digitalWrite(B, LOW);  //B
 digitalWrite(A, HIGH); //A
 }
 //6
 if (Counter == 6){
 digitalWrite(D, LOW);  //D
 digitalWrite(C, HIGH); //C
 digitalWrite(B, HIGH); //B
 digitalWrite(A, LOW);  //A
 }
 //7
 if (Counter == 7){
 digitalWrite(D, LOW);  //D
 digitalWrite(C, HIGH); //C
 digitalWrite(B, HIGH); //B
 digitalWrite(A, HIGH); //A
 }
 //8
 if (Counter == 8){
 digitalWrite(D, HIGH); //D
 digitalWrite(C, LOW);  //C
 digitalWrite(B, LOW);  //B
 digitalWrite(A, LOW);  //A
 }
 //9
 if (Counter == 9){
 digitalWrite(D, HIGH); //D
 digitalWrite(C, LOW);  //C
 digitalWrite(B, HIGH); //B
 digitalWrite(A, LOW);  //A
 }
}

See the example of that name in the IDE

See: File -> Examples -> 02.Digital -> StateChangeDetection

I've seen example earlier and I've tried doint it but it also didn't work.

Please post the code with your attempt at using state change detection and describe what the problem was

Your code in the first post won't compile. Maybe you want to fix that first? Did you post the right file?

Also, what button? There is no button code in your sketch at all. Small wonder the button doesn't work.

I forgot to change one thing before posting code here it's fixed now.

int Counter = 0;
#define A 12
#define B 11
#define C 10
#define D 9
void setup() {
  Serial.begin(9600);
  pinMode(8, OUTPUT);
  pinMode(D, OUTPUT);// D
  pinMode(C, OUTPUT);// C
  pinMode(B, OUTPUT);// B
  pinMode(A, OUTPUT);// A
  digitalWrite(8, LOW);
}
void loop() {
 digitalWrite(8, HIGH);
 Counter = Counter +1;
 delay(1000);
 Serial.print(Counter);
 //0 
 if (Counter == 0){
 digitalWrite(D, LOW);  //D
 digitalWrite(C, LOW);  //C
 digitalWrite(B, LOW);  //B
 digitalWrite(A, LOW);  //A
 }
 //1
  if (Counter == 1){
 digitalWrite(D, LOW);  //D
 digitalWrite(C, LOW);  //C
 digitalWrite(B, LOW);  //B
 digitalWrite(A, HIGH); //A
 }
 //2
 if (Counter == 2){
 digitalWrite(D, LOW);  //D
 digitalWrite(C, LOW);  //C
 digitalWrite(B, HIGH); //B
 digitalWrite(A, LOW);  //A
 }
 //3
 if (Counter == 3){
 digitalWrite(D, LOW);  //D
 digitalWrite(C, LOW);  //C
 digitalWrite(B, HIGH); //B
 digitalWrite(A, HIGH); //A
 }
 //4
 if (Counter == 4){
 digitalWrite(D, LOW);  //D
 digitalWrite(C, HIGH); //C
 digitalWrite(B, LOW);  //B
 digitalWrite(A, LOW);  //A
 }
 //5
 if (Counter == 5){
 digitalWrite(D, LOW);  //D
 digitalWrite(C, HIGH); //C
 digitalWrite(B, LOW);  //B
 digitalWrite(A, HIGH); //A
 }
 //6
 if (Counter == 6){
 digitalWrite(D, LOW);  //D
 digitalWrite(C, HIGH); //C
 digitalWrite(B, HIGH); //B
 digitalWrite(A, LOW);  //A
 }
 //7
 if (Counter == 7){
 digitalWrite(D, LOW);  //D
 digitalWrite(C, HIGH); //C
 digitalWrite(B, HIGH); //B
 digitalWrite(A, HIGH); //A
 }
 //8
 if (Counter == 8){
 digitalWrite(D, HIGH); //D
 digitalWrite(C, LOW);  //C
 digitalWrite(B, LOW);  //B
 digitalWrite(A, LOW);  //A
 }
 //9
 if (Counter == 9){
 digitalWrite(D, HIGH); //D
 digitalWrite(C, LOW);  //C
 digitalWrite(B, HIGH); //B
 digitalWrite(A, LOW);  //A
 }
}

In example there was const int buttonPin = 2; and const int ledPin = 13; but I tried using pinMode(8, OUTPUT) as button (I didn't use arduino for some time and didn't remember how to do stuff so I looked to old sketches from simple projects we did in school that had buttons in them and I tried copying htem and making them work as I wanted).

A pin connected to a button should have a pinMode() of INPUT or better still INPUT_PULLUP with appropriate wiring and logic in the sketch

If a button was an output, you would have to be making it go up and down as you watch. Pity those kind of buttons don't exist, they would be cool.

1 Like

They might. My GF had a receiver where the volume knob turned when you used the remote control…

a7

Save that one for April 1.

They’re $22 so I’m going to have to have an application before I order one.
Maybe one of those boxes that has the hand that shuts it off … without the hand.
You could have an application that completely disconnected from the mains eliminating phantom power, I suppose.

Mouser part # 653-A8GS-P1283 if anyone has an application.

Interesting way of looking at it, that is from the perspective of the button sending/writing a signal to the microcontroller. To follow that logic through, to test the state of the button, that would imply something like if (digitalWrite(button))

Instead, you have to look at it from the perspective of the microcontroller and that the button is an input device and you are reading it to see what state it is in. if (digitalRead(button))

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.