Hey guys,
I have a problem when using map() function to map 0 - 1023 to 0 - 5000. I have attached the code and print screen of serial monitor output indicating the error. For the love of god I don't know why this problem occurs. So can anyone help me. Please refer to the print screen of serial monitor for the problem.
yaantey:
So what is the problem and what can I do to correct it?
Well, I could repeat myself...
Or here is the same advice I already gave in code (untested):
int fsrPin = 0;
int samples[8];
// no need to globally define j and k, define them when you use them.
void setup()
{
Serial.begin(9600);
pinMode(fsrPin, INPUT);
}
void loop()
{
for(int j=0; j<=7; j++)
{
int currentReading = analogRead(fsrPin);
Serial.print("Analog Reading = ");
Serial.print(currentReading,DEC);
samples[j] = map(currentReading, 0, 1023, 0, 5000); // convert to 5V and save in the array
Serial.print(", Voltage in mV = ");
Serial.println(samples[j],DEC);
delay (3000);
}
Serial.println("---------------------------------------");
delay (500);
}
Edit: removed comment on the array deceleration. I misread the for-loop.