Go Down

Topic: pinbal machine (Read 122 times) previous topic - next topic

DonvanRaak75

Hello,

My name is Don, 43 years old and I am building a pinbal machine from scratch.
I am new with Arduino but I am learning.

Here's a question mabye somebody can help me with.

In the pinbal machine there are a lot of rolloverswitches to make a game. These switches are multiplexed with a HEF4067BP IC so the Arduino mega only recieves 5 wires. This works like a charme.
Press switch 15, and it wil show on the monitor.
But I want a Led to be lit in the playfield.
So I write digitalWrite (pin22, HIGH); And this happens, for about 3 seconds and then its low again. Why? The program did not tel it to go LOW.

If I look on the internet , the answer is a lot of times "look at blink without delay". But I don't want it to blink, and I have multiple Led's not one.

A lot of different things I have tried allready and understood the idea, but I am lost in all the information that I find on the net. And I don't realy know wich line to follow anymore.
So can anybody give me some pointers/tips/ideas?


Thanks,
Don




PaulRB

#1
Aug 25, 2019, 05:02 pm Last Edit: Aug 25, 2019, 05:04 pm by PaulRB
Post your code in code tags. Many forum readers use smartphones and tablets and can't open .ino attachments. If the code is too large to post in code tags (you get an error when you press post) then make a cut-down version of your sketch containing just enough to demonstrate the problem. (Quite often, while making the cut-down version, you figure out what the problem was yourself.)

A schematic would also be very helpful. If using Fritzing, use the schematic view, not the breadboard view.

DonvanRaak75

int val = 0;      // variabele om de read waarde op te slaan
int A_zero = 8;   // puls A0 op pin 8
int A_one = 9;    // puls A1 op pin 9
int A_two = 10;   // puls A2 op pin 10
int A_three = 11; // puls A3 op pin 11
int z = 12;       // pulsen A0,A1,A2,A3 maken samen een signaal om 
                  // schakelaar 1 t/m 16 te onderscheiden en uit te lezen
int Snow_S = 22;  // led Snow_S op pin 22                 
int Snow_N = 23;  // led Snow_n op pin 23
                 
void setup() {

  pinMode(z, INPUT);         // maakt de digitale pin "z" een INPUT
  pinMode(A_zero, OUTPUT);   // maakt de digitale pin A0 een output
  pinMode(A_one, OUTPUT);    // maakt de digitale pin A1 een output
  pinMode(A_two, OUTPUT);    // maakt de digitale pin A2 een output
  pinMode(A_three, OUTPUT);  // maakt de digitale pin A3 een output
  pinMode(Snow_S, OUTPUT);   // maakt de digitale pin Snow_S een output
  pinMode(Snow_N, OUTPUT);   // maakt de digitale pin Snow_N een output
  Serial.begin(9600);

}

void loop() {

  // Select address 0000
  digitalWrite(A_zero, LOW);
  digitalWrite(A_one, LOW);
  digitalWrite(A_two, LOW);
  digitalWrite(A_three, LOW);
  if (digitalRead(z) == 1) {
    Serial.println("Switch pressed is 1");
    digitalWrite (Snow_S,HIGH);
    delay(100);
 
  }

  // Select address 0001
  digitalWrite(A_zero, HIGH);
  digitalWrite(A_one, LOW);
  digitalWrite(A_two, LOW);
  digitalWrite(A_three, LOW);
  if (digitalRead(z) == 1) {
    Serial.println("Switch pressed is 2");
    digitalWrite(Snow_N,HIGH);
    delay(100);
  }

  // Select address 0010
  digitalWrite(A_zero, LOW);
  digitalWrite(A_one, HIGH);
  digitalWrite(A_two, LOW);
  digitalWrite(A_three, LOW);
  if (digitalRead(z) == 1) {
    Serial.println("Switch pressed is 3");
    delay(100);
  }

  // Select address 0011
  digitalWrite(A_zero, HIGH);
  digitalWrite(A_one, HIGH);
  digitalWrite(A_two, LOW);
  digitalWrite(A_three, LOW);
  if (digitalRead(z) == 1) {
    Serial.println("Switch pressed is 4");
    delay(100);
  }

  // Select address 0100
  digitalWrite(A_zero, LOW);
  digitalWrite(A_one, LOW);
  digitalWrite(A_two, HIGH);
  digitalWrite(A_three, LOW);
  if (digitalRead(z) == 1) {
    Serial.println("Switch pressed is 5");
    delay(100);
  }

  // Select address 0101
  digitalWrite(A_zero, HIGH);
  digitalWrite(A_one, LOW);
  digitalWrite(A_two, HIGH);
  digitalWrite(A_three, LOW);
  if (digitalRead(z) == 1) {
    Serial.println("Switch pressed is 6");
    delay(50);
  }

  // Select address 0110
  digitalWrite(A_zero, LOW);
  digitalWrite(A_one, HIGH);
  digitalWrite(A_two, HIGH);
  digitalWrite(A_three, LOW);
  if (digitalRead(z) == 1) {
    Serial.println("Switch pressed is 7");
    delay(100);
  }

  // Select address 0111
  digitalWrite(A_zero, HIGH);
  digitalWrite(A_one, HIGH);
  digitalWrite(A_two, HIGH);
  digitalWrite(A_three, LOW);
  if (digitalRead(z) == 1) {
    Serial.println("Switch pressed is 8");
    delay(100);
  }

  // Select address 1000
  digitalWrite(A_zero, LOW);
  digitalWrite(A_one, LOW);
  digitalWrite(A_two, LOW);
  digitalWrite(A_three, HIGH);
  if (digitalRead(z) == 1) {
    Serial.println("Switch pressed is 9");
    delay(100);
  }

  // Select address 1001
  digitalWrite(A_zero, HIGH);
  digitalWrite(A_one, LOW);
  digitalWrite(A_two, LOW);
  digitalWrite(A_three, HIGH);
  if (digitalRead(z) == 1) {
    Serial.println("Switch pressed is 10");
    delay(100);
  }

  // Select address 1010
  digitalWrite(A_zero, LOW);
  digitalWrite(A_one, HIGH);
  digitalWrite(A_two, LOW);
  digitalWrite(A_three, HIGH);
  if (digitalRead(z) == 1) {
    Serial.println("Switch pressed is 11");
    delay(100);
  }

  // Select address 1011
  digitalWrite(A_zero, HIGH);
  digitalWrite(A_one, HIGH);
  digitalWrite(A_two, LOW);
  digitalWrite(A_three, HIGH);
  if (digitalRead(z) == 1) {
    Serial.println("Switch pressed is 12");
    delay(100);
  }

  // Select address 1100
  digitalWrite(A_zero, LOW);
  digitalWrite(A_one, LOW);
  digitalWrite(A_two, HIGH);
  digitalWrite(A_three, HIGH);
  if (digitalRead(z) == 1) {
    Serial.println("Switch pressed is 13");
    delay(100);
  }

  // Select address 1101
  digitalWrite(A_zero, HIGH);
  digitalWrite(A_one, LOW);
  digitalWrite(A_two, HIGH);
  digitalWrite(A_three, HIGH);
  if (digitalRead(z) == 1) {
    Serial.println("Switch pressed is 14");
    delay(100);
  }

  // Select address 1110
  digitalWrite(A_zero, LOW);
  digitalWrite(A_one, HIGH);
  digitalWrite(A_two, HIGH);
  digitalWrite(A_three, HIGH);
  if (digitalRead(z) == 1) {
    Serial.println("Switch pressed is 15");
    delay(100);
  }

  // Select address 1111
  digitalWrite(A_zero, HIGH);
  digitalWrite(A_one, HIGH);
  digitalWrite(A_two, HIGH);
  digitalWrite(A_three, HIGH);
  if (digitalRead(z) == 1) {
    Serial.println("Switch pressed is 16");
    delay(100);
  }

}

PaulRB

#3
Aug 25, 2019, 05:13 pm Last Edit: Aug 25, 2019, 08:02 pm by PaulRB

noiasca

So I write digitalWrite (pin22, HIGH); And this happens, for about 3 seconds and then its low again. Why? The program did not tel it to go LOW.
a RESET (?) could cause this problem.
Add a Serial.print in the setup to see, if your controller resets before the LED goes off.

by the way, which microcontroller are you using?
DE: Wie man Fragen postet:
1. was hat man (Sketch und Hardware)
2. was SOLL es machen
3. was macht es: IST (Fehlverhalten, Fehlermeldungen, Serial.Output ...)
4. Eine Frage stellen bzw. erklären was man erwartet

david_2018

How do you have the LEDs wired?  Did you use a current-limiting resistor?  Is it possible you are drawing so much current it is causing the arduino to reset?


Not related to your question about the LED, but using multiplexed inputs with delay() statements between reads seems a very poor choice for rollover switches on a pinball machine. With sixteen switches, and 100mS delay between each switch, the switches will only get read once every 1.6 seconds, and you will only detect the switch being closed if it is closed at the exact time it is read.  Instead of an analog multiplexer, a couple of 8-bit parallel to serial shift registers would be much faster, and more suitable for reading the switches from an interrupt routine, since this application needs a fairly fast response time.

PaulRB


DonvanRaak75

Hello,

Thank you all for the replies.

I would like to change the delay's. I am reading and trying to change this with millis, so I downloaded some libraries about this subject. Also about debouncing the switches without the use of delay.
Maby you some good ones I should look in to.

Shift registers are not that clear to me, and I see something in state machine. But I think that I am making a mess in my mind to set things up.

A reset, I could try that.

The Led's on my breadboard are connected from the pin to earth with a 220 ohm resistor (each)
In the actual machine the arduino mega should turn on a solenoid (12V) via a optocoupler (5V)
The serialprint is not needed in the end. For now it is only to know that it works.

Don.

Paul__B

OK, now to facilitate discussion.

You need to go and read the forum instructions so that you can go back and modify your original post (not re-post it) - using the "More -> Modify" option below the right hand corner of your post - to mark up your code as such using the "</>" icon in the posting window.  Just highlight each section of code (or output if you need to post that) from the IDE and click the icon.

In fact, the IDE has a "copy for forum" link to put these markings on a highlighted block for you so you then just paste it here in a posting window.  But even before doing that, don't forget to use the "Auto-Format" (Ctrl-T) option first to make it easy to read.  If you do not post it as "code" it can easily be quite garbled and is always more difficult to read.

It is inappropriate to attach it as a ".ino" file unless it is clearly too long to include in the post proper.  People can usually see the mistakes directly and do not want to have to actually load it in their own IDE.  And that would also assume they are using a PC and have the IDE running on that PC.

Also tidy up your blank space.  Do use blank lines, but only between complete functional blocks.

Go Up