Trouble Getting an Array to digitalWrite

Hey All,
I’m working on some code to control LEDs with an IR Remote. I’d like to toggle mulitiple pins with a single IR signal using an array. I’ve created a function to do this but I can’t seem to properly call it.

What do I need to do to properly call the function? Serial reporting results below.

// the FET Shield uses pin 3 so we lose that functionality on the UNO - Design flaw of the sheild for sure.

#include <IRLib.h>

int RECV_PIN = A4;

int LED_1 = 13;
int LED_2 = 4;
int LED_3 = 5;

int allPins[] = {13, 4, 5};
int arrayPins_state = LOW;

IRrecv My_Receiver(RECV_PIN);
IRdecode My_Decoder;
IRdecodeHash My_Hash_Decoder;

void setup()
{
  pinMode(LED_1, OUTPUT);
  pinMode(LED_2, OUTPUT);
  pinMode(LED_3, OUTPUT);

  //  arrayWrite(allPins, arrayPins_state);  //mac

  My_Receiver.enableIRIn(); // Start the receiver
  Serial.begin(9600);
  delay(1000);
  Serial.print("Ready!");
}

void loop() {
  if (My_Receiver.GetResults(&My_Decoder)) {//Puts results in My_Decoder
    My_Hash_Decoder.copyBuf(&My_Decoder);//copy the results to the hash decoder
    My_Decoder.decode();
    Serial.print("real decode type:");
    Serial.print(Pnames(My_Decoder.decode_type));
    Serial.print(" value: 0x");
    Serial.println(My_Decoder.value, HEX);
    My_Hash_Decoder.decode();
    Serial.print("Hash decode: 0x");
    Serial.println(My_Hash_Decoder.hash, HEX); // Do something interesting with this value
    Serial.println("");

    if ((My_Hash_Decoder.hash) == 0x95EB7802) {  // DVD/LD #0
      if (arrayPins_state != LOW) {
        arrayPins_state = LOW;
        Serial.print("Array OFF - From IR Signal 0x");
        Serial.println(My_Hash_Decoder.hash, HEX);
        Serial.println(" ");
      }
      else
        arrayPins_state = HIGH;
      arrayWrite(allPins, arrayPins_state);  //mac
      if (arrayPins_state == HIGH) {
        Serial.print("Array ON - From IR Signal 0x");
        Serial.println(My_Hash_Decoder.hash, HEX);
        Serial.println(" ");
      }
      Serial.println(arrayPins_state);
    }
    delay(500);
    My_Receiver.resume();
  }
}

void arrayWrite(int pins[], int val) {
  for (int i = 0; i == (sizeof(pins) / sizeof(int)); i++) {
    digitalWrite(pins[i], val);
    Serial.println("Proof positive, the array is being called");
  }
}

As for reporting:
Serial.println(arrayPins_state);
shows in fact that the arrayPins_state is changing from 1 to 0 and 0 to 1
However
Serial.println(“Proof positive, the array is being called”);
never shows up.

A array is passed by reference. Inside the function sizeof() is done on the pointer to pins aka the array allPins.

  for (int i = 0; i == (sizeof(pins) / sizeof(int)); i++) {

Starting with i = 0, while i is some non-zero value, do some stuff and then increment i. How many times is that loop going to iterate?

Does the number zero ring a bell?

Haha, yeay, even if you could pass a array like that it still doesn’t work indeed…

Maybe you want something like (+comments)

// the FET Shield uses pin 3 so we lose that functionality on the UNO - Design flaw of the sheild for sure.

#include <IRLib.h>

const byte RECV_PIN = A4; //byte big enough

/* Useless to have variables and a array with tha same...
int LED_1 = 13;
int LED_2 = 4;
int LED_3 = 5;
*/

const byte LedPins[] = {13, 4, 5}; //byte is big enough
bool ledsState = LOW; //bool is big enough

IRrecv My_Receiver(RECV_PIN);
IRdecode My_Decoder;
IRdecodeHash My_Hash_Decoder;

void setup()
{
  //Make all LedPins output
  for(byte i = 0; i < sizeof(LedPins); i++){ //LedPins is a byte so no need to devide the size
    pinMode(LedPins[i], OUTPUT);
  }
  
  //  arrayWrite(allPins, arrayPins_state);  //mac

  My_Receiver.enableIRIn(); // Start the receiver
  Serial.begin(9600);
  //delay(1000); //Even ready without delay
  Serial.print("Ready!");
}

void loop() {
  if (My_Receiver.GetResults(&My_Decoder)) {//Puts results in My_Decoder
    My_Hash_Decoder.copyBuf(&My_Decoder);//copy the results to the hash decoder
    My_Decoder.decode();
    Serial.print("real decode type:");
    Serial.print(Pnames(My_Decoder.decode_type));
    Serial.print(" value: 0x");
    Serial.println(My_Decoder.value, HEX);
    My_Hash_Decoder.decode();
    Serial.print("Hash decode: 0x");
    Serial.println(My_Hash_Decoder.hash, HEX); // Do something interesting with this value
    Serial.println("");

    if ((My_Hash_Decoder.hash) == 0x95EB7802) {  // DVD/LD #0
      toggleLeds();
      /*
      if (ledsState != LOW) {
        ledsState = LOW;
        Serial.print("Array OFF - From IR Signal 0x");
        Serial.println(My_Hash_Decoder.hash, HEX);
        Serial.println(" ");
      }
      else
        ledsState = HIGH;
      arrayWrite(allPins, arrayPins_state);  //mac
      if (arrayPins_state == HIGH) { //That's what you just checked with the it!
        Serial.print("Array ON - From IR Signal 0x");
        Serial.println(My_Hash_Decoder.hash, HEX);
        Serial.println(" ");
      }
      Serial.println(arrayPins_state);
      */
    }
    //delay(500); //why a evil delay?
    My_Receiver.resume();
  }
}

void toggleLeds() {
  ledsState = !ledsState; //toggle state
  for(byte i = 0; i < sizeof(LedPins); i++) {
    digitalWrite(LedPins[i], val);
    Serial.println("Proof positive, the array is being called");
  }
}

Yay that works! Thanks Septillion!

Here’s the cleaned up code.

// the FET Shield uses pin 3 so we lose that functionality on the UNO - Design flaw of the sheild for sure.

#include <IRLib.h>

const byte RECV_PIN = A4; //byte big enough

const byte LedPins[] = {13, 4, 5}; //byte is big enough
bool ledsState = LOW; //bool is big enough

IRrecv My_Receiver(RECV_PIN);
IRdecode My_Decoder;
IRdecodeHash My_Hash_Decoder;

void setup()
{
  //Make all LedPins output
  for(byte i = 0; i < sizeof(LedPins); i++){ //LedPins is a byte so no need to devide the size
    pinMode(LedPins[i], OUTPUT);
  }
  
  My_Receiver.enableIRIn(); // Start the receiver
  Serial.begin(9600);
  Serial.print("Ready!");
}

void loop() {
  if (My_Receiver.GetResults(&My_Decoder)) {//Puts results in My_Decoder
    My_Hash_Decoder.copyBuf(&My_Decoder);//copy the results to the hash decoder
    My_Decoder.decode();
    Serial.print("real decode type:");
    Serial.print(Pnames(My_Decoder.decode_type));
    Serial.print(" value: 0x");
    Serial.println(My_Decoder.value, HEX);
    My_Hash_Decoder.decode();
    Serial.print("Hash decode: 0x");
    Serial.println(My_Hash_Decoder.hash, HEX); // Do something interesting with this value
    Serial.println("");

    if ((My_Hash_Decoder.hash) == 0x95EB7802) {  // DVD/LD #0
      toggleLeds();


    My_Receiver.resume();
  }
}
}
void toggleLeds() {
  ledsState = !ledsState; //toggle state
  for(byte i = 0; i < sizeof(LedPins); i++) {
    digitalWrite(LedPins[i], ledsState);
    Serial.println("Proof positive, the array is being called");
  }
}