Go Down

Topic: Multiple switch with multiple Leds (Read 577 times) previous topic - next topic

NimaRezaie

Well...I want to build a cryptographer machine. For example, when I press A, I want G to light up but the next time I'm pressing A, I want Q to light up. I want it to change anytime I'm pressing A or other alphabets. For example take NIMA as a plain text. When I press N, F lights up. When I press I, K lights up. When I press M, Q lights up. Finally when I press A, C lights up. But next time that I'm pressing these buttons(N, I, M, A), I want the machine to give me different alphabets. I hope I've made it vividly clear.
Thank you for your useful advice. And something else. Sorry about the way I write...Not that much good in English! :)

Paul__B

#16
Aug 17, 2019, 11:57 pm Last Edit: Aug 17, 2019, 11:59 pm by Paul__B
OK, that explains the 26 keys and LEDs.

So, the rules are, only one key at a time is ever pressed, if more that one is pressed, that would be invalid.  And only one LED ever illuminates at a time.

A Nano would perform this task perfectly on its own.  You have an array of 6 by 5 keyswitches (not all positions are necessarily used, or actually, you can have four "control" buttons to perform special functions).

And you have an array of LEDs which shares the same 6 columns.

So on the Nano, you have six pins to control the columns, five "row" pins to read the buttons and five "row" pins through 330 Ohm resistors to drive LEDs.  Total 16 pins, plenty on the Nano.

You digitalWrite all the columns as LOW to start but have the pinMode as INPUT, the button rows to INPUT_PULLUP and the LED rows as INPUT.

To read the buttons, you set one column at a time as OUTPUT, read the rows in turn looking for one that is LOW because the button at that cross is pressed, then that column back to INPUT and go on to the next.

To illuminate one LED, you set its column only as OUTPUT, its row as OUTPUT and write (only) the row HIGH.  To turn it off, you set the column as INPUT, the row as INPUT and write it LOW.  If you do not write it LOW again, it would effectively be INPUT_PULLUP and you could get a dim glow on the LEDs.

So your program then consists of spending most of the time with the desired LED illuminated, but periodically (every time millis() increases by 10) switching the LED off, reading all the buttons and deciding on the next action.  If there is no change, you go back to illuminating the same LED for another 10 ms.

Do not think that this is complex.  It is easy enough to build the code step by step and no less complicated than fiddling with 52 separate pins!

NimaRezaie

#17
Aug 18, 2019, 01:16 pm Last Edit: Aug 18, 2019, 01:23 pm by NimaRezaie
Um...I didn't quit understand. I see 16 switches and 64 leds.
And are these supposed to be wired on a breadboard?
And can I do it with a Uno? Because maybe I want to use the Uno for other purposes later.

Paul__B

#18
Aug 18, 2019, 02:15 pm Last Edit: Aug 18, 2019, 02:16 pm by Paul__B
When you get diagrams here, you get what you get!  :smiley-eek: These are the diagrams I managed to find to explain the concept of a matrix of pushbuttons or LEDs in case you have not encountered it before.  For your purpose the matrix in each case is 6 columns and five rows but I am not going to draw that one specially for you.  :smiley-roll:

It is up to you to determine how to construct your Enigma.  :smiley-lol:  That may well depend on how permanent you want this device to be.  A UNO is a poor board for making these sorts of things (or in fact, much at all).  A Nano with header pins fitted will indeed mount to a breadboard and at about $3 from eBay, you might as well just build the thing and keep it when you get it all working, but your switches and LEDs are gong to be the tricky bit.


NimaRezaie

#19
Aug 18, 2019, 02:36 pm Last Edit: Aug 18, 2019, 02:38 pm by NimaRezaie
Well...as you know I haven't encountered matrix used in arduino projects and that's why I didn't understand. I tried so many mechanical machines to build this thing but it didn't get anywhere with those simple settings and easy to crack codes. So I decided to go for something electronic  in which I was a beginner but at least I had the passion to learn about it. I just wanted to make sure if this project is possible to work on which I understood yes...Damn right it's possible. But as the first person answered my question said, I have to start from the beginning and experience some Aha moments rather than jumping into the main project at first...
If it's possible for you, please explain the matrix of the leds and switches a bit more simpler for me...
Thanks a million! :)

dougp

If it's possible for you, please explain the matrix of the leds and switches a bit more simpler for me...
You will find that, as a rule, this forum is averse to explaining in detail subjects which have been dissected countless times already.  Search the interwebs, and this forum especially, with terms like "LED multiplexing" and "keyboard matrix".  You will surely find dozens if not hundreds of results.
Everything we call real is made of things that cannot be regarded as real.  If quantum mechanics hasn't profoundly shocked you, you haven't understood it yet. - Niels Bohr

No private consultations undertaken!

Paul__B

On the other hand, if we see we are working with someone who is actually doing the work, we will usually "jolly them along" stepwise.

If you are serious about this project, and it is eminently doable, then I suggest you order a couple (two or three) Nanos from eBay.  For breadboarding, they are vastly more practical than the UNO and you need to look at them as "building blocks" (Lego) that you have a number of and like a serious set of Lego, you do not always want to pull one model apart just to make another.  :smiley-lol:

You refer to a breadboard, so I presume you have one, or will get one along with the Nanos.  For use on a breadboard, you solder the header pins along the sides (forget about the six pin header on top) but for a permanent project, you would be soldering connections directly to those pads.  You can then either build your full Enigma synthesiser, or start learning about arrays with 9 LEDs as 3 by 3.

You can practice simply illuminating LEDs one by one in a pattern, and later work on the input keys.  So there is no fear of the complexity, you do it step by step.Ready or not?

noiasca

reading your post #15 immediately ENIGMA came in my mind.

this: https://www.google.com/search?client=firefox-b-d&q=enigma+arduino
brought me there https://www.instructables.com/id/Make-your-own-Enigma-Replica/

I guess there are tons of similar project out there.

If you try to read the buttons with resistor network and if you use addressable LEDs like WS2811/Neopixel/APA106 one can easily do such a project with an UNO.

but do your homework:
SEARCH for ideas.
LEARN how to read lot of buttons and
LEARN how to set "lot" of LEDs
CHOSE your final design.
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

Paul__B

I would seriously advise against attempting to read 26 buttons using a resistor network.  :smiley-roll:

You might come back and suggest using A0 to A5 with 5 buttons each.  Even that I suggest would be ridiculous.  :smiley-eek:

A Nano (people have this crazy thing about UNOs - they are really impractical!) will do the job perfectly easily, more simply and reliably using buttons and simple LEDs wired up in matrices.  No requirement for multi-colours was suggested here.

NimaRezaie

Thank you all guys for your perfect advice! Specially you guys Noisca and Paul...
Paul I'll keep that in mind("what you said about getting ideas.") :D

noiasca

just found an analog keypad for 16 buttons and thought it's worth posting to this thread:
https://www.aliexpress.com/item/33007278026.html
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

Paul__B


Go Up