My tinkercad circuit is not working

int data = 2;
int oe = 5;
int store = 3;
int shift = 4;

int seqNorm[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14};

void setup()
{
  pinMode(data, OUTPUT);
  pinMode(oe, OUTPUT);
  pinMode(store, OUTPUT);
  pinMode(shift, OUTPUT);
}

void sequenceNormal()
{
  for(int i=0; i < 14; i++){
    digitalWrite(oe, HIGH);
    shiftOut(data, store, shift, seqNorm[i]);
  }
}

void sequenceReverse()
{
  int seqRev[] = {14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
  for(int j=14; j > 0; j--){
    digitalWrite(oe, HIGH);
    shiftOut(data, store, shift, seqRev[j]);
  }
}

void loop()
{
  sequenceNormal();
  delay(100);
  
  sequenceReverse();
  delay(100);
}

I want to make a dazzling LED animation with 15 LEDs. It is not working when I start the simulation. The LEDs are not glowing. Could you help me solve this problem?

There is no error

This lools like an error because it is an array overflow at index 14 in
seqRev[]

Post a schematic diagram.

seqNorm[] has 15 items (thus, the index goes from 0 to 14) while seqRev[] has 14 so you can't do that for() starting with 14.
Either add an item to seqRev[] (I suppose it's the 0), or change the for() to start from 13.

It is not clear what device you are talking to but maybe it needs a matching LOW written to it after sending the data.

Where is this function defined?

/OE is active LOW. So at least write it LOW and leave it.

There is no harm using the HIGH/LOW matching calls, but the data is broadside loaded, I think, so doing serves no purpose.

a7

You could of course be right but I was hoping to see the schematic before indulging in too much speculation about the behaviour of the chip this program is going to be talking to.

1 Like

Yes, thanks. I think there's something wrong with the call altogether.

This found in the body of a loop

  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, LSBFIRST, pattern);
  digitalWrite(latchPin, HIGH);

shows the three signals that count, /OE doesn't enter into it at all. so I like @build_1971 want to know what shiftOut function @emir38501 is using, and where the code came from as well as the actual part that is attached.

Out over the end of my surfboard again, sry.

From the wokwi documentation for the 74595 shift register:

const int dataPin = 2;   /* DS */
const int clockPin = 3;  /* SHCP */
const int latchPin = 4;  /* STCP */

void setup() {
  pinMode(dataPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(latchPin, OUTPUT);
}

int pattern = 0b10101010;
void loop() {
  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, LSBFIRST, pattern);
  digitalWrite(latchPin, HIGH);
  delay(500);
  pattern = ~pattern; // Invert the pattern
}

a7

I can say with some degree of confidence that shifOut() is an Arduino inbuilt function: https://docs.arduino.cc/language-reference/en/functions/advanced-io/shiftOut/

I would still like to know what the target device (SPI chip?) of all this is though.

Well, if this function belongs to the core, then it would be good to know the prototype ...
And to know what shift register is connected...

I would recommend to put some delay in the for loops. The sequence might be sent faster to the leds than your eyes can see...

... and I've just noticed this:

Ah yes, a 74595 shift register. That is certainly a possibility.
However, in the admittedly unlikely case that he has picked a CD4094 shift register, then the LOW and HIGH (there is called a strobe) would be reversed. However, I'd be surprised if TinkerCad even had such an ancient relic in their device palette. I've found a use for them driving Vacuum Fluorescent displays because you can coax up to 20 volts out of them.

The code is not working.

The device is an 74HC595 shift register.

Your call to shiftOut does not match the required pattern:

Why are you sending integers instead of bit patterns?

1 Like

You do need to call OE to be set LOW if its not externally tied LOW ; The 595 wont outout anything if this isnt kept LOW, I assume OE is connected to the arduino @emir38501 is using, Another option is just tie it direclty to ground

Do you have pin 10 of the 595 tied to 5V , This is reset and needs to be held high for the 595 to function.

This is the function shiftout calls and as above it expects a byte/bit pattern such as

shiftOut(dataPin, clockPin, LSBFIRST, 0b10101010);

or

int pattern = 0b10101010;

shiftOut(dataPin, clockPin, LSBFIRST, pattern);
void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, byte val) {
  int i;

  for (i = 0; i < 8; i++) {
    if (bitOrder == LSBFIRST)
      digitalWrite(dataPin, !!(val & (1 << i)));
    else
      digitalWrite(dataPin, !!(val & (1 << (3 - i))));

    digitalWrite(clockPin, HIGH);
    digitalWrite(clockPin, LOW);
  }
}

No, no it is not. Now the responses do all add up to enough information for you to solve the problem.

If you want our my help, I'll need you to

  • post the code you are using
  • post a schematic diagram of your circuit
  • supply a detailed description of the problem

by which I mean not "it doesn't work", but what it is doing that it should not, or not doing that it should. I don't actually recall you ever saying what it it is supposed to do, so you might. I can infer your goal from the code even in its current condition, but let's just be sure.

As you work, if any of those three things change, and you want more help, post them again. The entire altered sketch and/or the new wiring arrangement and/or the description of the new problem.

Imagine that we'd like to be in the room with you. You are our eyes and ears.

OK IC

What means that?

a7

I see some hope that, incrementally, we are going to be able to reverse engineer a schematic diagram out of the titbits of information which are gradually revealed in this thread.

I feel a missing gnd lead coming...