Speratic Operation

I have a sketch that does some weird things. I am able to get it to do what I want on a basic level (3-position switch that turns LED strip 3 different colours) but I am having trouble keeping it stable, the LEDs will turn on for a bit and turn off, randomly. Also the code acts completely differently once unplugged from the USB port and left to the wall power. Here is the code for reference and problem solving. The jist of the code is to have 3 positions (states) one is red, one blue and one is off.

Click on the link in the blue box that says: “click here to start download from sendspace”
It is the actual .ino file I have been working on.

Please help me, and thanks!

EDIT: I have added a circuit diagram ( well to the best of my ability with the software I have) and a direct download for the code.
Once again, I want to be able to have 3 different states that I can switch between for my LED strip. Three different LED patterns. The only stuff that I wrote starts at line 45 and goes to line 79. Everything else is just copied from the LED sketch that I downloaded from the LED site, that code is required for the configuration of the LEDs.

Circuit Diagram.bmp (750 KB)

LED_TEST.ino (5.2 KB)

How about attaching the code:
Additional Options, Browse to your locally stored file, Attach the file.

Hi, also a CAD or picture of a hand drawn circuit diagram would also help.
How are you powering your LEDs?
I hope not from the 5V on the arduino board, this is limited in current, and really supplying an array of LEDs is not what it is for.

Tom...... :slight_smile:

void loop() {
  switch1State = digitalRead(switch1Pin);
  if (switch1State == HIGH) {
    send_1M_pattern(pattern_test_red, 10, 70);
  }
  else  {
    
    }
    delay(1)
;switch3State = digitalRead(switch3Pin);
  if (switch3State == HIGH) {
    send_1M_pattern(pattern_test_blue, 10, 70);
  }
  else  {
    
    }
    delay(1)
;switch2State = digitalRead(switch2Pin);
  if (switch2State == HIGH) {
    send_1M_pattern(pattern_test_off, 10, 70);
  }
  else  {
    
    }
    
  }

My eyes hurt.
Did sendspace do that to your code?

What is the smallest sketch that still exhibits this behaviour?

The correct spelling for your title is "Sporadic Operation".

If you go back to your original post and click "modify" you will be able to change it.

+1 for a short sketch that illustrates and isolates the problem.

...R

CrossRoads:
How about attaching the code:
Additional Options, Browse to your locally stored file, Attach the file.

Yeah I'll do that. I'll have to post this afternoon though. I'll also include some kind of circuit diagram

TomGeorge:
Hi, also a CAD or picture of a hand drawn circuit diagram would also help.
How are you powering your LEDs?
I hope not from the 5V on the arduino board, this is limited in current, and really supplying an array of LEDs is not what it is for.

Tom...... :slight_smile:

Yeah, I'll get you a circuit diagram this afternoon. And no, I am not powering by the 5V, I am powering it by way of Vin which is supplying 12V from a wall wart.

I added a better link for both the sketch and diagram.

Are your digitalRead() calls returning the values you expect according to the switch positions? Since the code you posted doesn't tell you, you probably don't know; Serial.print statements to print out the values would let you find out.

PeterH:
Are your digitalRead() calls returning the values you expect according to the switch positions? Since the code you posted doesn't tell you, you probably don't know; Serial.print statements to print out the values would let you find out.

I have added the serial.print and weird things are happening. With the switch connected to GND and a digital pin, when activated it does show what it should but it does not stay as a solid line. There is interference from other digital pins connected to the same GND. I am so confused.

Hi, please complete your circuit diagram and show all your power supply wiring.

Thank you

Tom..... :slight_smile:

Perhaps it's because I'm thick, but I have no idea what your code is supposed to do.

Why are there huge arrays of identical values? Wouldn't one copy of that value do?

Why are there lines and lines of NOP assembler instructions?

Also there is another file pgmspace.h that seems to have some code in it and you haven't included that.

What does send_1M_pattern() do?

What does send_strip() do?

...R

Robin2:
Perhaps it's because I'm thick, but I have no idea what your code is supposed to do.

Why are there huge arrays of identical values? Wouldn't one copy of that value do?

Why are there lines and lines of NOP assembler instructions?

Also there is another file pgmspace.h that seems to have some code in it and you haven't included that.

What does send_1M_pattern() do?

What does send_strip() do?

...R

Ok, so a lot of the code is actually from the LED strip control sketch that I downloaded from the LED strip manufacturer. All I did (well attempting to do) is take the portion of that code that actually sends the final command to the LEDs and link it to a digital pin state. So the "send_1M_pattern()" sends the appropriate section of code from the set of colour combinations. (If you look above there is about 6 different Hexacode type sections that determine the colour of the LEDs.
As for the "send_strip()" portion, once again it is required for the LED strip operation and I just copied the code over. I believe it just tells the Arduino to actually send the pattern over to the LEDs.

It's messy, I am a beginner and I'll also post a link to just the default LED strip control.

Sorry, I still don't understand enough to offer any advice.

And my text editor tells me the rows and colums in those large arrays are identical.

...R