Hi, I'm working on an Arduino UNO board and am using C programming language. I seem to have a problem correctly returning an array from function. I did some reading on this and understand the fact that a function cannot return the array itself, but instead a pointer.
This seems to work for the first ~25 values of the array and then I get inconsistent results. I print off the values in the function as they are gathered and they are correct (I'm reading digital 0/1's). However, once I return the values to my main function every value after ~25 is a very large number (several 1000's) when I clearly saw only 0/1's in the function. Here's my code that's giving issues. Any thoughts?
This seems to work for the first ~25 values of the array and then I get inconsistent results. I print off the values in the function as they are gathered and they are correct (I'm reading digital 0/1's). However, once I return the values to my main function every value after ~25 is a very large number (several 1000's) when I clearly saw only 0/1's in the function. Here's my code that's giving issues. Any thoughts?
Code:
#include <LiquidCrystal.h>
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
int * sensorReadbackAll;
void setup() {
//lcd init and digital pin states
}
void loop() {
//do stuff
sensorReadbackAll = sensorReadAll();
for(i=0;i<64;i++){
lcd.setCursor(10,0);
lcd.print(sensorReadbackAll[i]);
lcd.setCursor(7,0);
lcd.print(i);
delay(100);
}
//do more stuff
}
int * sensorReadAll(){
int i = 0;
int sensorDataAll[64];
while(i < 64){
//stuff
sensorDataAll[i] = digitalRead(tempSensorPin);
lcd.setCursor(6,0);
lcd.print(sensorDataAll[i]);
delay(100);
i++;
}
return(sensorDataAll);
}