Idk alot about coding but this is a message i am getting alot:xit status 1 invalid types 'int[int]' for array subscript

#include <IRremote.h>

 #include <Irremote.h>
 
 #define first_key 48703
 #define second_key 58359
 #define third_key 539 
 #define fourth_key 25979
 int receiver_pin = 10;

 int first_led_pin = 7;
 int second_led_pin = 8;
 int third_led_pin = 5;
 int fourth_led_pin = 4;
 int led = (0,0,0,0);
IRrecv receiver(receiver_pin);
decode_results output;
 
 void setup() {
  // put your setup code here, to run once:

Serial.begin(9600);
receiver.enableIRIn();
pinMode(first_led_pin, OUTPUT);
pinMode(second_led_pin, OUTPUT);
pinMode(third_led_pin, OUTPUT);
pinMode(fourth_led_pin, OUTPUT);
}

void loop() {// put your main code here, to run repeatedly:
if (receiver.decode(&output)) {
unsigned int value = output.value;
switch(value) {
case first_key:
if(led[1] == 1) {
digitalWrite(first_led_pin, LOW);
led[1] = 0;
}else{
digitalWrite(first_led_pin, HIGH);  
led[1] = 1;
}
break;
case second_key:

if(led[2] == 1) {
digitalWrite(second_led_pin, LOW);
led[2] = 0;
}else{
digitalWrite(second_led_pin, HIGH);
led[2] = 1;
}
break;
case third_key:

if(led[3] == 1){
digitalWrite(third_led_pin, LOW);
led[3] = 0;
}else{
digitalWrite(third_led_pin, HIGH);
led [3] = 1;
}
break;
case fourth_key:

if (led[4] == 1);{
digitalWrite(fourth_led_pin, LOW);
led[4] = 0;
}else{
digitalWrite(fourth_led_pin, HIGH);
led[4] = 1;  
}
break;
}
Serial.println(value);
receiver.resume();
}
}

please repost your code using </>

you should similar post the error messages with provide a line # and additional information

int led = (0,0,0,0);

it looks like you intend the led to be an array. it could be defined

int led [] = (0,0,0,0);

but the array elements are indexed starting at zero. so the following line would not reference an element of the array but the next thing in memory

                led[4] = 1;

This is also a problem:

if (led[4] == 1); {

That is not how you define an array, you define an integer initialized with 0.

int led[] = {0,0,0,0};

should work better.

Auto-formating your code and posting it as code would have helped to read it.

1 Like

Here is a more efficient version:

#include <IRremote.h>

const int numKeys = 4;
const int receiver_pin = 10;
const unsigned int keyCodes[numKeys] = {48703, 58359, 539, 25979};
const int ledPins[numKeys] = {7,8,5,4};

IRrecv receiver(receiver_pin);
decode_results output;

void setup() {
  // put your setup code here, to run once:

  Serial.begin(9600);
  receiver.enableIRIn();
  for (int i = 0; i < numKeys; i++) 
  {
    pinMode(ledPins[i], OUTPUT);
    digitalWrite(ledPins[i], LOW);
  }
}

void loop() {// put your main code here, to run repeatedly:
  if (receiver.decode(&output)) {
    unsigned int value = output.value;
    for (int i = 0; i < numKeys; i++)
    {
      if (value == keyCodes[i])
      {
        digitalWrite(ledPins[i], !digitalRead(ledPins[i]));
        break;
      }
    }
    Serial.println(value);
    receiver.resume();
  }
}

Oops.

Edit: sorry, that one's already covered.

Contrary to popular belief, "alot" is not a word.

its not working

. . .is about the most useless thing you could post on this forum.

Works great for me. I tested it in TinkerCad. Pretty simple program.

What is it doing or not doing?