Hi all, I am a new guy in Arduino programming , I am trying to use Array to store 2 FSR data to find the difference of the 2 readings.
the program is running not as per my expectation, can everyone in this forum provide your kind assistance to help me..
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(13,OUTPUT);
}
void loop() {
fsrReading=analogRead(A0);
for (i=0;i<2;i=i+1){
Serial.println(" pls input your pressure: ");
while(fsrReading==0){
}
pressread[i]=fsrReading;
}
pressDiff=pressread[0]-pressread[1];
Serial.println(pressread[i]);
Serial.println(pressread[0]);
Serial.println(pressread[1]);
Serial.print("pressure different :");
Serial.println abs(pressDiff);
First of all you did not read the recommended thread for new users.
Then read: How to get the best out of this forum.
Then using tags </> fix the post of your code.
Now about your code.
A. Missing a "}" at the end of the code;
B. The variable "fsrReading" has not been set;
C. This while doesn't make any sense.
" while (fsrReading == 0) {
}"
Hi RV mineirin,
Appreciated much to your advice. I have amended my code as below stated:-
// This code is to intake 2 difference press the FSR which is fsrpin =A0 and assigned into array. Every 2x compress the FSR , the program will call up the array 0 and 1 to obtain the different of 2 FSR readings.
int pressread[2];
int fsrpin=A0;
int fsrReading;
int pressDiff;
int i;
int dT=1000;
void setup() {
Serial.begin(9600);
pinMode(fsrpin,INPUT);
}
void loop() {
fsrReading=analogRead(fsrpin);
for (i=0;i<2;i=i+1){
Serial.println("Pls input your pressure : "); // waiting for FSR to be press for 1st array reading.
while(fsrReading==0){} // while FSR not being press, it won't not proceed to next activities
fsrReading=analogRead(fsrpin);
pressread[i]=fsrReading; // after pressing the FSR , the fsrReading from the fsrpin=A0 assign the reading into array
}
pressDiff=pressread[0]-pressread[1]; // find the different between 2 array readings.
Serial.println(pressread[0]); // print out the array[0] reading
Serial.println(pressread[1]); // print out the array[1] reading
Serial.print("pressure different :");
Serial.println abs(pressDiff); // print out the 2 array difference substracted result
Serial.println("");
delay(dT);
}
Questions encountered :
the FSR not proceeding to next step after the 1st press of FSR.
the fsrReading does not assign any reading into the array.
I can't think off where went wrong with this code program, pls advise...
thank you.. for your time that is highly appreciated..
How is the FSR wired? Post a schematic showing how the FSR should be wired.
It is unlikely that the FSR will ever read 0. What is the range of FSR outputs? Do you know?
Read the forum guidelines to see how to properly post code. Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.