control 3x 7 segment single digits with 6 buttons

ok, sooo.. i'm looking on how to control (3) 7 segment single digit displays with 6 buttons.. each segement led to be controlled by 2 buttons each.. count up/count down

IE:

SEGMENT SEGMENT SEGMENT
BUT- BUT+ BUT- BUT+ BUT- BUT+

so, i know how to make 1 button count up and another count down.. but now i'd like to have a neat simple code that would work without having this huge thing of code.. can it be done or do i have to code each button individually as i expect?

EDIT: i meant i can make 2 buttons work with 1 segment.. but not all 6 buttons and 3 segments

if it can be done can somebody please show me how it would be done.. thank you

By "segment", do you mean "digit"? What is

this huge thing of code..

yeah - says so in the very first sentence... 7 segment single digit....

exactly what i'm trying to do.. except the buttons will be underneath instead of above...

Ruffsta:
yeah - says so in the very first sentence... 7 segment single digit....

I don't think so, as you talk about counting up/down with a segment. A segment can only be on or off. You are not off to a good start if you don't know the names of things.

yeah, 2 button PER 7 segment 1 digit led = making the the digit count up and down.. basically a counter

i can control 1 digit with 2 buttons.. but now i wanna control 3 digits with 6 buttons.. i think i was pretty clear on what i'm trying to accomplish and provided a picture..

button.. 7 segment 1 digit... what am i naming wrong? lol

anyways, not here to argue.. i'm here trying to accomplish something.. so i can go without the hard time thank you

It's no argument, it's a given with this technology. You have to use the right terminology or you will give and get all the wrong answers. Trust me, I've been doing it a long time.

Why can you make 1 digit work with two buttons, but not 3 with 6 buttons?

You were asked what you meant by "this huge thing of code"

Post your code so people know what problems you're having. Explain what you tried.

i can..

nvm.. i'm just gonna have to accept that's gonna be alot of coding vs a shortened code to do the damn job

This is where confusion entered:

Ruffsta:
ok, sooo.. i'm looking on how to control (3) 7 segment single digit displays with 6 buttons.. each segement led to be controlled by 2 buttons each.. count up/count down

When what, I think, you meant was:

Ruffsta:
ok, sooo.. i'm looking on how to control (3) 7 segment single digit displays with 6 buttons.. each segement led digit to be controlled by 2 buttons each.. count up/count down

Another approach: Use two switches to generate the count up and count down signals. Use a third switch to progressively cycle through which digit the count switches act upon.

Based on your graphic the switches are virtual. True?

Use arrays and a for loop to avoid repeating code

Why is your code so super secret?

dougp:
I think, you meant was:

Another approach: Use two switches to generate the count up and count down signals. Use a third switch to progressively cycle through which digit the count switches act upon.

Based on your graphic the switches are virtual. True?

however you wanna read/interpet it.. and i am using an arduino mega with real buttons.. that image was from a game made for the nintendo ds created by a friend and i'm trying to re-create it with the arduino..

UKHeliBob:
Use arrays and a for loop to avoid repeating code

i never said i was a great coder... i'm still new to arduino - i just gave up for awhile and now i wanna try to accomplish some old projects..

evanmars:
Why is your code so super secret?

it's not.. just i code like a beginner

right now i'm just testing a code.. it works, but it could be better and shorter... i just dunno how

``````const int a=2;
const int b=3;
const int c=4;
const int d=5;
const int e=6;
const int f=7;
const int g=8;
const int buttonPin = 12;
int no = 0;
int buttonState = 0;
int lastButtonState = 0;

void setup() {

pinMode(buttonPin, INPUT);
pinMode(a, OUTPUT);
pinMode(b, OUTPUT);
pinMode(c, OUTPUT);
pinMode(d, OUTPUT);
pinMode(e, OUTPUT);
pinMode(f, OUTPUT);
pinMode(g, OUTPUT);
}
void loop(){
if (buttonState != lastButtonState)
{
if (buttonState == HIGH) {
no++;
}

else {
}
}
lastButtonState = buttonState;
////////////////////////
switch(no)
{
case 0:
digitalWrite(a, LOW);
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, LOW);
digitalWrite(e, LOW);
digitalWrite(f, LOW);
digitalWrite(g, HIGH);
break;

case 1:
digitalWrite(a, HIGH);
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, HIGH);
digitalWrite(e, HIGH);
digitalWrite(f, HIGH);
digitalWrite(g, HIGH);
break;

case 2:
digitalWrite(a, LOW);
digitalWrite(b, LOW);
digitalWrite(c, HIGH);
digitalWrite(d, LOW);
digitalWrite(e, LOW);
digitalWrite(f, HIGH);
digitalWrite(g, LOW);
break;
case 3:
digitalWrite(a, LOW);
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, LOW);
digitalWrite(e, HIGH);
digitalWrite(f, HIGH);
digitalWrite(g, LOW);
break;
case 4:
digitalWrite(a, HIGH);
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, HIGH);
digitalWrite(e, HIGH);
digitalWrite(f, LOW);
digitalWrite(g, LOW);
break;

case 5:
digitalWrite(a, LOW);
digitalWrite(b, HIGH);
digitalWrite(c, LOW);
digitalWrite(d, LOW);
digitalWrite(e, HIGH);
digitalWrite(f, LOW);
digitalWrite(g, LOW);
break;
case 6:
digitalWrite(a, LOW);
digitalWrite(b, HIGH);
digitalWrite(c, LOW);
digitalWrite(d, LOW);
digitalWrite(e, LOW);
digitalWrite(f, LOW);
digitalWrite(g, LOW);
break;

case 7:
digitalWrite(a, LOW);
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, HIGH);
digitalWrite(e, HIGH);
digitalWrite(f, HIGH);
digitalWrite(g, HIGH);
break;

case 8:
digitalWrite(a, LOW);
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, LOW);
digitalWrite(e, LOW);
digitalWrite(f, LOW);
digitalWrite(g, LOW);
break;
case 9:
digitalWrite(a, LOW);
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, LOW);
digitalWrite(e, HIGH);
digitalWrite(f, LOW);
digitalWrite(g, LOW);
break;
default: no=0; break; } }
``````

so.. if that's just for 1 button to count up.. i'll need a code to count down for the second button.. and then do that whole code 2 more times...

3 buttons to count up and 3 buttons to count down.. as shown in the example pic i provided

starting to see my dilemma?

Ruffsta,
you need to create some arrays and use the array contents to write to Mega Ports to drive the LEDs.
For example, say for each digit you connected g-f-e-d-c-b-a of the digit to say PL6-5-4-3-2-1-0
The first array would map a number to be displayed to the segments to make that number appear.

``````byte fontArray [] = {
0b00111111, // 0   not used-g-f-e-d-c-b-a, with 1 = segment on
0b00000110, // 1
0b01011011, // 2
0b01001111, // 3
etc.
};
with the segments arranged thusly:
a
f       b
g
e      c
d
[code]
Then to display a number, you look up the font for the digit to be displayed and send it to the port:
[code]
PORTL = fontArray[digit0];
PORTK = fontArray[digit1];
PORTF = fontArray[digit2];
PORTC = fontArray[digit3];
PORTB = fontArray[digit4];
PORTA = fontArray[digit5];
``````

If you only have 3 digits, then just use 3 ports. Those ports all have 8 pins brought out to headers.
You will need a current limit resistor for each segment of the 7-segment display.

To read the 6 buttons, you can read the buttons individually, and act on them, with a little delay after reading, say 200mS so you could press & hold & count up or down 5 times a second:

``````void loop(){
if (digitalRead(button0) == LOW){ // assumes button0 is type INPUT_PULLUP and button connects pin to Gnd when pressed
if (digit0 > 0){        // check to not go below 0
digit0 = digit0 -1;
}
}
if (digit0 < 9){
digit0 =digit0 + 1; // check to not go above 9
}
}
PORTL = fontArray(digit0);
// repeat for the next digit or two
:
:
delay (200); // limit changes to 5 times a second
} // end of loop
``````

You can see how even within that there is repetition, but there are only 3 digits so it's not too bad.
[/code]
[/code]

Here's a YT video illustrating reading multiple buttons with essentially one routine. The data for each button has an array address and the routine runs in a for() loop. The demonstration only uses two inputs but is easily expanded to any reasonable number. This obviates the need for separate debounce code for every switch.

it will (2x) 2 digits and (4x) 1 digit displays

only showed an example pic for (3x) 1 digits.. the entire project..

also not shown will be the last button with an rgb led to select level..
green=easy, yellow=medium, red=hard.. this button will control the left side digit displays as well call a new game every time the level is changed.. as well as an on/off switch with and led for power indicator.

so as you can see, there is alot more going on than the (3x) 1 digit displayed in pic 1

my buddy made this game for the DS awhile back.. my intent is to reproduce it with the arduino.. put it in an enclosure with a mini arduino board and battery pack and send it to him - as well make a copy for me lol.

evanmars:
Why is your code so super secret?

the code isn't.. but i don't need everyone making the same projects.. everyone should try to be unique and not take the credit and claim the project to be theirs. i've programmed for the ds and made computer games and software.. some things i just want to remake with the arduino.. some projects i do want to keep private.

so now that i have posted the project.. how many are gonna attempt it now? see, i was trying make something unique.. those that attempt to do this same project is a copycat and couldn't come up with the idea on their own.so it's not so much of the coding snipets.. more trying to keep entire projects to myself.

Ruffsta:
see, i was trying make something unique.. those that attempt to do this same project is a copycat

... like you, since the design pattern you used is a common one that has been replicated numerous times on various websites. There isn't any shame, all programmers do it, but please stop pretending.

yeah ok.. pretending my ass.. this project has never been asked or done on here.. but now that i posted my project attempt others will do it cause they couldn't come up with the idea themselves and you know it!