Make binary output from one input

Thread Starter

carking1996

Joined Aug 2, 2014
3
How would one take a single input (e.g. from a button) and make that output a binary code (5 wires for maximum 16 buttons). E.g. button 1 would poll some type of device which would then output the binary signal "1".
 

MrChips

Joined Oct 2, 2009
30,795
You have to come up with a better description of your problem.
I read your post ten times and still haven't a clue of what you are asking.
 

shteii01

Joined Feb 19, 2010
4,644
Normally I would say: device polls the button. But when I say device here, I am talking about microcontroller.

It seems that your devices work very differently from mine.
 

MrChips

Joined Oct 2, 2009
30,795
It is called a 16-line to 4-bit priority encoder:

There are 8-line to 3-bit priority encoders:

TTL - 74148
CMOS - MC14532

It is just as easy to do with a microcontroller.
 

Thread Starter

carking1996

Joined Aug 2, 2014
3
Of course, if you press B, gettiing 2 would requre the inputs to be sent through wires as

01 00 00 00, and 3 as
11 00 00 00

That's what the middle man chip there is, but what could do the job for me?

Edit: Alright. I see.
 

aaro4130

Joined Aug 2, 2014
2
Well what im wondering is , say you press button 4, and it's on the 4th input, how would a priority encoder change that into 4 in binary. I'm working with carking on this btw.

So would a microcontroller be the correct way to go in this case?. We'd only be using 5 lines of binary (max 16), because our controllers won't be using 255 buttons :p.

They will be connected to 5 pins in the GPIO, which would be polled by Python, with >20 GPIO pins we could fit 2 controllers with a 5 pin interface easily. This is the only roadblock atm.
 

shteii01

Joined Feb 19, 2010
4,644
Well what im wondering is , say you press button 4, and it's on the 4th input, how would a priority encoder change that into 4 in binary. I'm working with carking on this btw.

So would a microcontroller be the correct way to go in this case?. We'd only be using 5 lines of binary (max 16), because our controllers won't be using 255 buttons :p.

They will be connected to 5 pins in the GPIO, which would be polled by Python, with >20 GPIO pins we could fit 2 controllers with a 5 pin interface easily. This is the only roadblock atm.
Ok. Lets start with the ground floor.

How many inputs?
How many outputs?
 

MrChips

Joined Oct 2, 2009
30,795
Instead of polling 5 pins in GPIO why not have 16 buttons and one serial output line when ever a button is pressed?
(Then you can have as many buttons as you wish.)
 

aaro4130

Joined Aug 2, 2014
2
I'm very very sorry if I sound dense or anything. I'm just new to this type of stuff.

Would it be easy to do this? Or easier with something like a serial interface. The big thing is the fact that we need to use GPIO pins.
 

shteii01

Joined Feb 19, 2010
4,644
I'm very very sorry if I sound dense or anything. I'm just new to this type of stuff.

Would it be easy to do this? Or easier with something like a serial interface. The big thing is the fact that we need to use GPIO pins.
11 buttons can be done with either 11 pins or 22 pins.

The output can either be 1 pin or 5 pins. I think 5 pin will be easier to implement, make sure receiver has 5 pins, that way the 1, 2, 4, 8, 16 don't matter because you setup receiver to associate the receiving pin with specific number. Say receiver Pin 1 goes from 0 volts to 5 volts, your software interprets that as 1 was sent. The receiver Pin 2 goes from 0 volts to 5 volts, the software interprets that as 2 was sent. The receiver Pin 3 goes from 0 volts to 5 volts, the software interprets that as 4 was sent.
 

ErnieM

Joined Apr 24, 2011
8,377
carking1996: If you press one and only one button at a time this is fairly simple to do using just some (33) diodes and some (5) resistors.

OK, that's a lot of parts but the basic idea is simple.

If there is a chance that two or more buttons can be pressed it is a still possible to do using some 74HC148 priority encoder ICs.

Here's one complication or simplification, depending on how you look at it: 15 buttons can be coded into 4 wires as states 1-15 (leaving state zero as "no button"). The 16th button needs another line which gives you another potential 16 buttons to scan, or you can just use the 5th line on the 16 button with no other encoding.

And welcome to the forums!
 

THE_RB

Joined Feb 11, 2008
5,438
Looks like a game or machine controller. It's almost certain the user will press more than one button at once, so a simple 16line to 4bit encoder (or a diode encoder) won't work.

I like MrChips suggestion of putting a small micro in there and then you just need a serial output wire.
 
Top