0
\$\begingroup\$

i have a project to controll lamp in cupboard. there are several button. okay, lets imagine there is 8 button. when i click 1st button its will turn on lamp 1, when i click button 2, lamp 2 is on. i use arduino and process it with decoder 3 to 8 bit decoder (ic 74138), but its not what i want, when i click button 1, lamp 1 is on, when i clicked button 2, lamp 2 is on but lamp 1 is turned off before i clicked off button? i study how decoder work, and then decoder just can active one output, while another output is deactive. the question is, how can i manage decoder, so the active output is can more than one? when i click button 1 lamp 1 is on, when i click button 2, lamp 2 is on, and lamp 1 also still on. and so on. need help :'( thank you

i attach my lamp condition now based on decoderenter image description here

asked Jan 27, 2016 at 4:34
\$\endgroup\$
3
  • \$\begingroup\$ You should draw a schematic with the schematic edit tool. I can't make sense of your question. \$\endgroup\$ Commented Jan 27, 2016 at 4:41
  • \$\begingroup\$ Or maybe you're trying to do something that would be better for a shift register...? \$\endgroup\$ Commented Jan 27, 2016 at 4:42
  • \$\begingroup\$ Draw up and post a 'truth table'. You will clear the logic in you own mind and everyone else's. You may even solve the problem yourself. \$\endgroup\$ Commented Jan 27, 2016 at 5:31

2 Answers 2

1
\$\begingroup\$

Dump the decoder. It is not the component for your desired operational scenario.

If you want to support 8 switches and (extrapolating here) 8 LEDs then you simply need a way to output 8 separate GPIO port bits to control each LED individually. Those 8 GPIOs could be direct port pins from your microcontroller or they could come from some type of software controlled expansion circuit.

One type of expansion circuit could be a simple 8-bit serial to parallel shift register. Software would pulse two port pins with data levels and a "clock" to shift the 8-bits out to the shift register.

Another approach would be to use an I2C I/O port chip. The simplest of these use the two port pins on the microcontroller to support the SCL and SDA protocol of the I2C bus where commands are sent to the external device to program it's registers. These registers in turn select whether the pins are inputs or outputs, input status, output state or whether there has been a state change interrupt detected for an input.

answered Jan 27, 2016 at 4:52
\$\endgroup\$
0
\$\begingroup\$

From the limited information you've given, it sounds like you want a so-called Thermometer Code (named after the appearance of a mercury-in-glass thermometer where the length of the mercury in the capillary increases with temperature). Also called a binary to unary decoder (I've used a slightly different definition than the Wiki page - sequence 0, 1, 11, 111, 1111, ... )

This is not a standard function- there is no standard IC that I can think of that performs this function without programming of some kind.

You can easily write C code to do this, or use a lookup table. For example, if n is the number you wish to decode to unary and i and n are int:

for (i=0;i<n;i++) ans = ans << 1 | 1; 

If ans is unsigned int you can hold 16 bits on an Arduino, if it's unsigned long you can hold 32 outputs. That means the maximum value that makes sense for n is 0x10 or 0x20 respectively, and the minimum is 0- all off.

Then the problem reduces to outputting the bits you need, which can be done directly to port pins (if you have enough) or to something like a 74HC595 shift register chain. In the latter case, you could create the unary number in the shift register directly (before you toggle the transfer clock), but you would be restricted to wiring the outputs in a particular order.

answered Jan 27, 2016 at 6:03
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.