Hello,
sorry if there is error in my language.
I want to know what is the problem with my code
const int LDR1 = A0;
const int LDR2 = A2;
const char SEPARATOR[] = ", \t";
void plotSignal(int n, int s[]) {
int i;
for (i = 0; i < n - 1; i++) {
Serial.print(s[i]);
Serial.print(SEPARATOR);
}
Serial.println(s[i]);
}
void ldrInit() {
pinMode(LDR1, INPUT);
pinMode(LDR2, INPUT);
}
int *ldrRead() {
int data[3];
data[0] = analogRead(LDR1);
data[1] = analogRead(LDR2);
data[2] = millis() / 1000;
plotSignal(3, data);
return data;
}
unsigned long last_millis = 0;
void setup() {
Serial.begin(9600);
ldrInit();
}
void loop() {
if (millis() - last_millis > 1000) {
int *data = ldrRead();
data[3] = 180;
plotSignal(3, data);
last_millis = millis();
}
}
So i want to read data from LDR sensor and print it in serial monitor. The problem is the value from void loop is different from what is initially read from inside the function. I am expecting the two data has the same value at least for the first two element in the array.
The schematics is in Schematics.jpg if you need it
and what I got from the output is in Monitor.png
thanks in advance
p.s. I am using Arduino Nano with old bootloader

