Make binary output from one input

Discussion in 'Embedded Systems and Microcontrollers' started by carking1996, Aug 2, 2014.

  1. carking1996

    Thread Starter New Member

    Aug 2, 2014
    3
    0
    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".
     
  2. MrChips

    Moderator

    Oct 2, 2009
    12,414
    3,353
    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.
     
  3. carking1996

    Thread Starter New Member

    Aug 2, 2014
    3
    0
    Here's an image.

    [​IMG]
     
  4. shteii01

    AAC Fanatic!

    Feb 19, 2010
    3,375
    494
    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.
     
  5. shteii01

    AAC Fanatic!

    Feb 19, 2010
    3,375
    494
    I think the problem is that in binary 1 is 0001, 2 is 0010, 3 is 0011, etc. So to tell us that "I press A, I get 1" is not really how it works.
     
  6. MrChips

    Moderator

    Oct 2, 2009
    12,414
    3,353
    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.
     
  7. carking1996

    Thread Starter New Member

    Aug 2, 2014
    3
    0
    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.
     
  8. aaro4130

    New Member

    Aug 2, 2014
    2
    0
    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.
     
  9. shteii01

    AAC Fanatic!

    Feb 19, 2010
    3,375
    494
    Ok. Lets start with the ground floor.

    How many inputs?
    How many outputs?
     
  10. MrChips

    Moderator

    Oct 2, 2009
    12,414
    3,353
    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.)
     
  11. aaro4130

    New Member

    Aug 2, 2014
    2
    0
    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.
    [​IMG]
     
  12. shteii01

    AAC Fanatic!

    Feb 19, 2010
    3,375
    494
    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.
     
  13. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    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!
     
  14. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
    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.
     
Loading...