Array data to function

I’m receiving byte data type wirelessly in a function (getData) from an external source and then placing it into a function (updateArray). In this function I’m placing the received data into an array. I know this is working properly because I can print the array and the printout matches the data sent. I pass the array from the updateArray function to another function (cntrlLED) where I want to use the array data to control some LED’s. My problem is that I can’t get the array values into my LED control variables( LEDOnHr = arr[i*cols + j]; ), all I get are zeros and ones. I’ve read quite a lot about arrays and pointers, but I just can’t seem to get the gist and figure out why I don’t get the variable I want. Can someone please show me what I’m doing wrong?
```
// Node00
#include <RF24.h>
#include <RF24Network.h>
#include <SPI.h>
#include <Wire.h>
RF24 radio(9, 10); // nRF24L01 (CE,CSN)
RF24Network network(radio); // Include the radio in the network
const uint16_t this_node = 00; // Address of our node in Octal format
int incomingdata[15];
//Create a structure to hold fake sensor data and channel data
struct Received {
  int incomingdata[15];
  //char
PinNum[8];// = {""};
};
Received received; //create struct objectt
//                  LED1  LED2  LED3  LED4  LED5  LEDTV LEDSIGN LEDLOT
byte LEDOnHr[8]    = { 5,  5,    7,    9,    9,    7,    10,    6    };
byte LEDOnMin[8]  = { 0,  30,  0,    30,  45,  0,    0,      0    };
byte LEDOffHr[8]  = { 11,  11,  11,  9,    11,  11,  11,    3    };
byte LEDOffMin[8]  = { 30,  0,    0,    10,  30,  0,    0,      0    };
byte LEDAM_On[8]  = { 1,  1,    1,    1,    1,    0,    1,      0    };  //1 or 0 when CheckedAsByte
byte LEDPM_On[8]  = { 0,  0,    0,    0,    0,    1,    0,      1    };  //1 or 0 when CheckedAsByte
byte LEDAM_Off[8]  = { 0,  0,    0,    0,    0,    0,    0,      1    };  //1 or 0 when CheckedAsByte
byte LEDPM_Off[8]  = { 1,  1,    1,    1,    1,    1,    1,      0    };  //1 or 0 when CheckedAsByte
byte LEDSun[8]    = { 1,  0,    0,    0,    0,    0,    1,      1,    };  //1 or 0 when CheckedAsByte
byte LEDMon[8]    = { 1,  1,    0,    1,    0,    0,    1,      0,    };  //1 or 0 when CheckedAsByte
byte LEDTue[8]    = { 1,  1,    1,    0,    1,    1,    1,      1,    };  //1 or 0 when CheckedAsByte
byte LEDWed[8]    = { 1,  1,    1,    0,    1,    0,    1,      0,    };  //1 or 0 when CheckedAsByte
byte LEDThr[8]    = { 1,  0,    1,    0,    0,    0,    1,      0,    };  //1 or 0 when CheckedAsByte
byte LEDFri[8]    = { 1,  0,    0,    0,    0,    0,    1,      0,    };  //1 or 0 when CheckedAsByte
byte LEDSat[8]    = { 1,  0,    0,    0,    0,    0,    1,      0,    };  //1 or 0 when CheckedAsByte
char *text[7] = {“Sun”, “Mon”, “Tue”, “Wed”, “Thr”, “Fri”, “Sat”};
const int myRows = 8;
const int myCols = 15;
int myArr[myRows][myCols] = {};
int k = 0;
int x = 0;
//===========
void setup()
{
  Serial.begin(115200);
  SPI.begin();
  Serial.println(F(“BuildinglightsGUI-RF24L_ForceTronics-EasyNetwork-ReceiverMaster”));
  Serial.println(“Network master is online…”);
  Serial.println("------------------------------------------------------------------");
  Serial.println(" ");
  radio.begin();
  network.begin(90, this_node); //(channel, node address)
  radio.setDataRate(RF24_2MBPS);
}

void loop()
{
  network.update();
  getData();
}
//==============================
void getData()
{
  if ( network.available() )  // Is there any incoming data?
  {
    RF24NetworkHeader header;   
    network.read(header, &received, sizeof(received)); // Read the incoming data
    if (header.from_node == 1)  // If data comes from Node 01
    {
      Serial.println(F(" “));
      Serial.println(F(”---------- Receiving GUI Variables ----------"));
      Serial.print(F(“Transmitter = “));
      Serial.println(header.from_node);
      updateArray(myArr, myRows, myCols);
    }
  }
}
void updateArray(int
arr, int rows, int cols)
{
  Serial.print(“LED Pin Number = “);
  Serial.println(PinNum[k]);
  k++;
  //data1 = data[0];
  for (int i = 0; i < 1; i++) {
    for (int j = 0; j < cols; j++) {
//+++ printout very array data = incoming data +++
      arr[i*cols + j] = received.incomingdata[j];
      Serial.print(“arr = “);
      Serial.print(arr[i*cols + j]);
      Serial.print(”\t”);
      Serial.print(”\t”);
      Serial.print(“index = “);
      Serial.print(j);
      Serial.print(”\t”);
      Serial.print(received.incomingdata[j]);
      Serial.println(”\t”);
//+++++++++++++++++++++++++++++++++++++++++++++++++
    }
  }
  Serial.println(" ");
  cntrlLED(myArr, myRows, myCols);   
}

* *
void cntrlLED(int arr, int rows, int cols)
{
  Serial.println(“in cntrlLED”);
  for (int i = 0; i < 1; i++) {
    for (int j = 0; j < cols; j++) {
      Serial.print(arr[i*cols + j]);
      LEDOnHr[i] = arr[i*cols + j];
      LEDOnMin[i] = arr[i*cols + j]; 
      LEDOffHr[i] = arr[i*cols + j];
      LEDOffMin[i] = arr[i*cols + j];

}
    Serial.println(" “);
    Serial.print(LEDOnHr[i]);
    Serial.print(”\t");
    Serial.print(LEDOnMin[i]); 
    Serial.print("\t");
    Serial.print(LEDOffHr[i]);
    Serial.print("\t");
    Serial.print(LEDOffMin[i]);
  }
}*
```

Did you mean for (int i = 0; i < rows; i++) { ?

I started out with

for (int i = 0; i < rows; i++) {

but everything printed 8 times, which didn’t make sense to me. Could it be caused by the rf radio if (network.available() ) statement ? So to answer your question, no I didn’t mean rows, I was using 1.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.