Pages: [1]   Go Down
Author Topic: Unit crashing on button press with multiple button setup  (Read 582 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

heya.

First off, I'm a noob to Arduino in general.  I've run through the tutorials that came with my kit and have a basic grasp at it.  Professionally, I'm a software engineer, so I have things covered on that front.

My problem is that I have a basic setup with a 7 segment LED that is working as intended, but I also have 3 buttons wired up on a separate breadboard that are causing me problems.  The 7 segment LED is wired up to digital ports 2-8.  The buttons are wired up to digital 10-12.  Button 12 responds as intended, however 10 and 11 cause the Arduino to apparently crash and reset. 

I've tried disconnecting input 12 to see if there was some sort of conflict between it and the other 2 buttons, but the results are the same.  All 3 are wired up the exact same.

Here's my code:
Code:
int buttona = 12;
int buttonb = 11;
int buttonc = 10;

int sega = 2;
int segb = 3;
int segc = 4;
int segd = 5;
int sege = 6;
int segf = 7;
int segg = 8;

int counter = 0;

byte numbers[10][7] = {{1,1,1,1,1,0,1},
                       {0,1,1,0,0,0,0},
                       {1,1,0,1,1,1,0},
                       {1,1,1,1,0,1,0},
                       {0,1,1,0,0,1,1},
                       {1,0,1,1,0,1,1},
                       {1,0,1,1,1,1,1},
                       {1,1,1,0,0,0,0},
                       {1,1,1,1,1,1,1},
                       {1,1,1,1,0,1,1}};

void displayNum(int num) {
  for (int i = 0;i<8; i++) {
    digitalWrite(i+2,numbers[num][i]);
  }
}

// the setup routine runs once when you press reset:
void setup() {               

  pinMode(buttona, INPUT);
  pinMode(buttonb, INPUT);
  pinMode(buttonc, INPUT);

  pinMode(sega, OUTPUT);     
  pinMode(segb, OUTPUT);     
  pinMode(segc, OUTPUT);     
  pinMode(segd, OUTPUT);     
  pinMode(sege, OUTPUT);     
  pinMode(segf, OUTPUT);     
  pinMode(segg, OUTPUT);     
 
  displayNum(0); 
}

// the loop routine runs over and over again forever:
void loop() {
  if (digitalRead(buttona) == 0) {
    if (counter < 9) counter++;
  }
  if (digitalRead(buttonb) == 0) {
    if (counter > 0) counter--;
  }
  if (digitalRead(buttonc) == 0) {
    counter = 0;
  }
 
  displayNum(counter);

  delay(500);

}

Images of my layout:


Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

realized i had my positive and negatives reversed on the other 2 buttons...  i guess this is what happens when you stare at something for too long...

This topic can be deleted...i am ashamed...
Logged

Brisbane, Australia
Offline Offline
Edison Member
*
Karma: 33
Posts: 1123
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This topic can be deleted...i am ashamed...
No need to be.  No smoke was released, no puppies were harmed, and others will learn along with you from this.  It's all good  smiley

Glad to see you got it all going,
Geoff
Logged

"There is no problem so bad you can't make it worse"
- retired astronaut Chris Hadfield

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

No need to be.  No smoke was released, no puppies were harmed, and others will learn along with you from this.  It's all good  smiley

Glad to see you got it all going,
Geoff

Yea, I got it working by fixing the positive/negative wires.  Still feel silly for trial and erroring it for so long without noticing something so simple.  Buuuut.  Got my 3 button setup working great.  First 2 buttons are for setting the counter, 3rd button now starts the countdown.  Got a working timer that counts down the 7Segment LED to 0 then plays an alternating buzzer noise and lights a red LED.  Pretty cool for my first custom self-learn project.  The tutorials and expertise on this site are invaluable.

Ended up using up all of my digitals however.  Is there a way to expand for more or perhaps cut down the amount needed for the 7 Segment.

Logged

Brisbane, Australia
Offline Offline
Edison Member
*
Karma: 33
Posts: 1123
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sure, look to either a MAX7219 which can be used to run several 7 segment displays, or even a 74HC595 or similar shift register can be used to drive one.  There are lots of examples of how to's.

Cheers ! Geoff
Logged

"There is no problem so bad you can't make it worse"
- retired astronaut Chris Hadfield

Pages: [1]   Go Up
Jump to: