Please help me, I am new to programming and am starting to experiment with Arduino

I am fairly new to Arduino, less new to programming although I didn't program hardware. I am trying to make a complex circuit that plays songs and flashes leds along to it, but i'm taking it one step at a time and before adding audio into it just want to make sure I can make it switch led patterns with the click of a button, but it isn't working and when I do code it correctly it still doesn't work, yet I can't find where my error is. (THIS IS JUST A PROTOTYPE)
(Almost all of the code isn't mine and was from somebody's project for led patterns)

#define t   30
#define t1  20
#define t2  100
#define t3  50
int buttonState;
int buttonPin = 13;
int pattern = 1;

void setup() {
  // set up pins 2 to 11 as outputs
  for (int i = 2; i <= 13; i++) {
    pinMode(i, OUTPUT);
  }
}

void loop(){

buttonState = digitalRead(buttonPin);
if(buttonState = HIGH);{
  pattern ++;
}

if(pattern > 7);{
  pattern = 1;
}

//left to right and right to left
while(pattern = 1);{
for(int i=2; i<14; i++){
digitalWrite(i, HIGH);
delay(t1);
digitalWrite(i+1, HIGH);
delay(t1);
digitalWrite(i+2, HIGH);
delay(t1);
digitalWrite(i, LOW);
delay(t1);
digitalWrite(i+1, LOW);
delay(t1);
}
for(int i=13; i>1; i--){
digitalWrite(i, HIGH);
delay(t1);
digitalWrite(i-1, HIGH);
delay(t1);
digitalWrite(i-2, HIGH);
delay(t1);
digitalWrite(i, LOW);
delay(t1);
digitalWrite(i-1, LOW);
delay(t1);
}
}
while(pattern = 1);{
int count = 13; // keeps track of second LED movement

  // move first LED from left to right and second from right to left
  for (int i = 2; i < 13; i++) {
    digitalWrite(i, HIGH);      // chaser 1
    digitalWrite(count, HIGH); // chaser 2
    count--;
    // stop LEDs from appearing to stand still in the middle
    if (count != 7) {
      delay(t2);
    }
  }

  // move first LED from right to left and second LED from left to right
  for (int i = 13; i > 2; i--) {
    digitalWrite(i, HIGH);      // chaser 1
    digitalWrite(count, HIGH); // chaser 2
    count++;
    // stop LEDs from appearing to stand still in the middle
    if (count != 8) {
      delay(t2);
    }
  }
}
while(pattern = 3);{
for(int i=2; i<14; i++){
  digitalWrite(i, HIGH);
  delay(t3);
}
for(int i=2; i<14; i++){
  digitalWrite(i, LOW);
  delay(t3);
}

for(int i = 14; i>=2; i--){
  digitalWrite(i, HIGH);
  delay(t3);
}
for(int i = 14; i>=2; i--){
  digitalWrite(i, LOW);
  delay(t3);
}
}
while(pattern = 4);{
for(int j = 2; j <= 13; j++){
  digitalWrite(j, HIGH);
  delay(t2);
  j=j+1;
  }
for(int j = 2; j <= 13; j++){
  digitalWrite(j, LOW);
  delay(t2);
  }

  for(int k = 15; k > 2; k--){
  digitalWrite(k, HIGH);
  delay(t2);
  k=k-1;
  }
for(int k = 15; k > 2; k--){
  digitalWrite(k, LOW);
  delay(t2);
  }
}
while(pattern = 5);{
 for(int pin = 13; pin >= 2; pin--)
  {
  digitalWrite(pin, HIGH);
  delay(t1);
  digitalWrite(pin+1, LOW);
  delay(t1);
  }
  for(int pin = 13; pin >= 2; pin--)
  {
  digitalWrite(pin+1, HIGH);
  delay(t1);
  digitalWrite(pin+2, LOW);
  delay(t1);
  }
  for(int pin = 13; pin >= 2; pin--)
  {
  digitalWrite(pin+2, HIGH);
  delay(t1);
  digitalWrite(pin+3, LOW);
  delay(t1);
  }
  for(int pin = 13; pin >= 2; pin--)
  {
  digitalWrite(pin+3, HIGH);
  delay(t1);
  digitalWrite(pin+4, LOW);
  delay(t1);
  }
    for(int pin = 13; pin >= 2; pin--)
  {
  digitalWrite(pin+4, HIGH);
  delay(t1);
  digitalWrite(pin+5, LOW);
  delay(t1);
  }
  for(int pin = 13; pin >= 2; pin--)
  {
  digitalWrite(pin+5, HIGH);
  delay(t1);
  digitalWrite(pin+6, LOW);
  delay(t1);
  }
  for(int pin = 13; pin >= 2; pin--)
  {
  digitalWrite(pin+6, HIGH);
  delay(t1);
  digitalWrite(pin+7, LOW);
  delay(t1);
  }
   for(int pin = 13; pin >= 2; pin--)
  {
  digitalWrite(pin+7, HIGH);
  delay(t1);
  digitalWrite(pin+8, LOW);
  delay(t1);
  }
  for(int pin = 9; pin >= 2; pin--)
  {
  digitalWrite(pin+8, HIGH);
  delay(t1);
  digitalWrite(pin+9, LOW);
  delay(t1);
  }
    for(int pin = 9; pin >= 2; pin--)
  {
  digitalWrite(pin+9, HIGH);
  delay(t1);
  digitalWrite(pin+10, LOW);
  delay(t1);
  }
  for(int pin = 9; pin >= 2; pin--)
  {
  digitalWrite(pin+10, HIGH);
  delay(t1);
  digitalWrite(pin+11, LOW);
  delay(t1);
  }
  for(int pin = 14; pin >= 2; pin--)
  {
  digitalWrite(pin+11, HIGH);
  delay(t1);
  }
  for(int pin = 13; pin >= 2; pin--)
  {
    digitalWrite(pin, LOW);
  delay(t1);
    }
  }
while(pattern = 6);
for(int j=2; j<14; j++){
  digitalWrite(j, LOW);
  delay(t);
  digitalWrite(j, HIGH);
  delay(t);
  digitalWrite(j-2, LOW);
  delay(t);
  digitalWrite(j, HIGH);
}
for(int k = 15; k>2; k--){
  digitalWrite(k, LOW);
  delay(t);
  digitalWrite(k, HIGH);
  delay(t);
  digitalWrite(k+2, LOW);
  delay(t);
  digitalWrite(k, HIGH);
}
for(int k = 2; k<14; k++){
  digitalWrite(k, LOW);
  delay(t);
  digitalWrite(k, HIGH);
  delay(t);
  digitalWrite(k-2, LOW);
  delay(t);
  digitalWrite(k, HIGH);
}
for(int k = 15; k>2; k--){
  digitalWrite(k, LOW);
  delay(t);
  digitalWrite(k, HIGH);
  delay(t);
  digitalWrite(k+4, LOW);
  delay(t);
  digitalWrite(k, HIGH);
}
for(int k = 2; k<14; k++){
  digitalWrite(k, LOW);
  delay(t);
  digitalWrite(k, HIGH);
  delay(t);
  digitalWrite(k-4, LOW);
  delay(t);
  digitalWrite(k, HIGH);
} 
}
while(pattern = 7);{
for(int j=2; j<14; j++){
  digitalWrite(j, HIGH);
  delay(t);
  digitalWrite(j+2, LOW);
  delay(t);
}
for(int k = 15; k>2; k--){
  digitalWrite(k, HIGH);
  delay(t);
  digitalWrite(k+2, LOW);
  delay(t);
  }
}

IMG_20220816_115628

Please post a schematic showing how those LEDs are connected.

It looks like they are in parallel with no current limit resistors. Where did you find that wiring scheme?

That conveys no useful information. What does the code do? How is that different from what you want?

When using hardware you also have to look at the hardware circuit.
You have several LEDS in series and no resistor. That is never going to work as the Arduino will only output a 5V singal which is not enough for those LEDs.

The laws of Physics don't give a dam if it is a prototype or not. They keep on working just as if it were the real thing.

Always sad when the comment doesn't match the code.

buttonState = digitalRead(buttonPin);
if(buttonState = HIGH);{
  pattern ++;
}

To start suggest you always use switch change in state rather than switch levels.

LEDs need a series resistor to limit the LED current flow.


if(buttonState = HIGH);{


if(buttonState == HIGH);{

= is not the same as ==

= for assignment, == for compare. In a while structure you want compare. And the ; at the end of the while will make the code below the while execute unconditionally. Lose the ; on each while.
All of your while structures are like that.

You mean == not =
And the ; after both statement makes it useless anyway.

Really these are beginners mistakes?

Are you using 3V3 or the 5V pin ?

Removed the ; and added == so it will run. But nothing in the loop can ever change the variable pattern, so once in that loop it will stay there forever. The same thing seems to happens on all your while loops.

Note: It's bad form to:

  1. Use your input pin as an output.
  2. Go off the end of a list.

Fair, I def should have put more. The code is meant to make 40 leds, effectively 10 since its just 10 rows of 4 flash in what right now is just patterns. There are no limit resistors as since it's powering so many without any external power and since these LEDs can take a lot I figured it wouldn't need any as they intake a high voltage anyways. The code should simply change the pattern upon the pressing of a 3 pin button. Ill make the schematics rq in a couple minutes

Oh ok ty! Ill change that and I can see why that would make sense. Ty for the help!

3.3v, the 5v pin can also power my switch without frying it, but 3.3v works fine so I figured no reason to change it.

1.) I see and I thought the same thing and was going to initially run a couple 9v batteries into the circuit, but to my surprise it worked fine when I plugged it in. Ill give the hardware another look fs tho, ty!
2.) Fair enough lmao just figured id put it out there just in case
3.) Oh yeah I need to fix that than ty!

Thank you! I see, so is my main problem that its in the void loop() function?

New to hardware, ive never programmed hardware before, and im still fairly beginning, just slightly less new to it, I did different software things before in not c languages.
Ty for the help! Ig I need to spend more time studying the basic functions

Not recommended for newbies to get into bad habits.

Use 5V logic levels on inputs that expect 5V logic levels.

Not adhering to proper engineering will some day bit you butt.
:astonished:

See post #4.

Oh ok, thank you!!! This really helps and I appreciate it!

Oh ok thank you! Ill check it out fs! I havent put any resistors on yet but I know I should to protect them! Thank you!

More than that, you need to protect the Arduino outputs.

Are buttons normally supposed to run on 5v than?