If loop breaking sketch

Hello all, first time here so sorry if this isn't the right place to post.

I cant manage to make a pretty simple sketch work, it seems adding an if statement makes the entire sketch do nothing.

int sense[] = {A0, A1};
int val[1];
int coil[] = {2, 3, 4};

void setup() {
  Serial.begin(9600); 
  pinMode(sense[0,1], INPUT);
  pinMode(coil[0,1,2], OUTPUT);
}

void loop() {

  val[0] = analogRead(sense[0]);
  val[1] = analogRead(sense[1]);
  Serial.println("ts1");


  if (val[0] < 180) {
    Serial.println("coil2 on");
    
    while(val[0] < 180){
      delay(1);
      val[0] = analogRead(sense[0]);
      Serial.println("wait");
    }
    
  }

  delay(1);
}

Commenting out the if loop makes ts1 appear correctly in the serial monitor, but as soon as the if is introduced nothing appears at all, despite ts1 being before the if loop.

A one element array has no element with the index 1

pinMode(coil[0,1,2], OUTPUT); Where have you seen this syntax?

First, there is no such thing as an if loop. An if statement makes a decision. It does NOT cause looping.

 pinMode(coil[0,1,2], OUTPUT);

This is NOT a valid use of the comma operator.

 pinMode(sense[0,1], INPUT);

This isn't either. There is no need to call pinMode() on pins to be used as analog pins. They are already INPUT and can not be made OUTPUT.

 Serial.println("ts1");

It would make more sense to print the value(s) read from the analog pins...

Ah I see, I was just messing around with the arrays. I didn't think those would be the problem, but everything is working fine now :slight_smile: . Thanks for the quick replies.

Ah I see, I was just messing around with the arrays. I didn't think those would be the problem

As a general rule always fix the things that are obviously wrong first, even if you don't think there is the slightest chance they are anything to do with the problem. Only when the obvious things are fixed sholud you look elsewhere for the problem.