74138 ic ..NEED help, any better way to simplify this code ?

i'm trying to simplify this code. somehow i cant get the correct output when i use the code below. the outputs i tested it manually one by one first combination of high and low. now i want to use a different method for easier.

4 led anode to cathode
pin 15 led 1 pin 11
pin 14 led 2 pin 10
pin 13 led 3 pin 9
pin 12 led 4 pin 8

TABLE 1 - COMBINATION
SETUP 1(A) 2(B) 3(C)
1 L L L
2 L L H
3 L H L
4 L H H
5 H L L
6 H L H
7 H H L
8 H H H

TABLE 2 - ACTIVE LED OUTPUT
SETUP 1 2 3 4 5 6 7 8
1 NO 1 NO 1,3 NO 1,2 NO 1,3,4
2 1 1 1 1,3 2,3 1,2 1,2,4 1,2,3,4
3 NO 1 NO 3 NO 1,2,3 NO 3,4
4 1,3 1,3 1 3 2,3,4 1,2,3,4 2,4 2,4
5 NO 1,2 NO 2,3,4 NO 2 NO 2,4
6 NO 1,2 1,2 1,2,3,4 2 2 2,4 2,4
7 NO 1,2,4 NO 4 NO 2,4 NO 4
8 1,4 1,2,4 4 2,4 2,4 2,4 4 4

thanks for the help

_74138Case.ino (2.36 KB)

Sorry for being thick and asking a dumb question but what are you trying to achieve other than simplying your code.

Are you trying to emulate a 74138 IC with an arduino or are you sending signals to an 74138?

Hi,
Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Can you explain what your code is supposed to do?
Do you have current limit resistors in series with the LEDs.

Thanks.. Tom.. :slight_smile:

I tink this will get you on the way

byte firstPins[3] = {13, 12, 11};
byte table1[][3] =
{
  {LOW, LOW, LOW},
  {LOW, LOW, HIGH},
  {LOW, HIGH, LOW},
  {LOW, HIGH, HIGH},
  {HIGH, LOW, LOW},
  {HIGH, LOW, HIGH},
  {HIGH, HIGH, LOW},
  {HIGH, HIGH, HIGH},
};

void setup()
{
  Serial.begin(250000);

  for (int firstCnt = 0; firstCnt < sizeof(firstPins); firstCnt++)
  {
    pinMode(firstPins[firstCnt], OUTPUT);
  }

}

void loop()
{
  if (Serial.available() > 0)
  {
    char first = Serial.read();

    if (first >= 'A' && first <= 'H')
    {
      for (int firstCnt = 0; firstCnt < sizeof(firstPins); firstCnt++)
      {
        Serial.print("pin = "); Serial.print(firstPins[firstCnt]);
        Serial.print(", value = "); Serial.println(table1[first - 'A'][firstCnt] == LOW ? "LOW" : "HIGH");
        digitalWrite(firstPins[firstCnt], table1[first - 'A'][firstCnt]);
      }
    }
    else
    {
      // bail out
      Serial.println("Silly");
      return;
    }
  }
}

The part in loop() simply loops through the 3 pin values in table1 for the given character (A..H). Subtracting 'A' from first selects the row in table1.

TomGeorge:
Hi,
Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Can you explain what your code is supposed to do?
Do you have current limit resistors in series with the LEDs.

Thanks.. Tom.. :slight_smile:

Controlling 74LS138, 3 - Line to 8 - Line Decoder / Demultiplexer, using Arduino « Funny Electronics , this is where i get my reference then i tried experiment a bit.

http://ecee.colorado.edu/~mcclurel/sn74ls138rev5.pdf, the data sheet ive been using.

i'm trying to find a substitute for ic 74595 because its not available in my local stores here.

thanks for the help

sterretje:
I tink this will get you on the way

byte firstPins[3] = {13, 12, 11};

byte table1[][3] =
{
  {LOW, LOW, LOW},
  {LOW, LOW, HIGH},
  {LOW, HIGH, LOW},
  {LOW, HIGH, HIGH},
  {HIGH, LOW, LOW},
  {HIGH, LOW, HIGH},
  {HIGH, HIGH, LOW},
  {HIGH, HIGH, HIGH},
};

void setup()
{
  Serial.begin(250000);

for (int firstCnt = 0; firstCnt < sizeof(firstPins); firstCnt++)
  {
    pinMode(firstPins[firstCnt], OUTPUT);
  }

}

void loop()
{
  if (Serial.available() > 0)
  {
    char first = Serial.read();

if (first >= 'A' && first <= 'H')
    {
      for (int firstCnt = 0; firstCnt < sizeof(firstPins); firstCnt++)
      {
        Serial.print("pin = "); Serial.print(firstPins[firstCnt]);
        Serial.print(", value = "); Serial.println(table1[first - 'A'][firstCnt] == LOW ? "LOW" : "HIGH");
        digitalWrite(firstPins[firstCnt], table1[first - 'A'][firstCnt]);
      }
    }
    else
    {
      // bail out
      Serial.println("Silly");
      return;
    }
  }
}



The part in loop() simply loops through the 3 pin values in table1 for the given character (A..H). Subtracting 'A' from *first* selects the row in *table1*.

Hey!
Thanks for the sample code you gave me, it help me a lot. especially the outputs..