Go Down

Topic: Using a Force Sensing Resistor and time input (Read 91 times) previous topic - next topic

SS_D9

So the code below measures how much force is exerted on the FSR. I would like to know what would I have to change in this code so that it can record for how long the FSR is being pressed for. So instead of "What force is exerted on the FSR?", I want to ask "How long is the FSR being pressed for?"

Any help will be most appreciated

Code: [Select]
#include<SoftwareSerial.h>
#include <Wire.h>
SoftwareSerial bluetooth_port(0, 1); //ports for Rx and Tx
int flexSensorPin; // The flex sensor for pin 0

void setup()
{

  Serial.begin(9600); // Start the serial transmission
}


void loop()
{

  flexSensorPin = analogRead(A0); // Flex sensor pin
  Serial.print(flexSensorPin);
  Serial.println("EOL");

  delay(100);

}

wvmarle

Look for state change detection (there's an example in the IDE).

In your case: pressed if the analog reading is higher (or smaller, depending on your wiring) than a certain threshold. Record the value of millis() when it goes from unpressed to pressed, and see how long it's been (compare to the then current value of millis()) whne it goes from pressed to unpressed.
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

Go Up