// Define a pin that we'll place the FSR on
// Remember to add a 10K Ohm pull-down resistor too.
int fsrPin = A0;
// Create a variable to hold the FSR reading
int fsrReading = 0;
// Define a pin we'll place an LED on
int ledPin = D2;
// Create a variable to store the LED brightness.
int ledBrightness = 0;
int switchPin = D3;
void setup()
{
// Set up the LED for output
pinMode(ledPin, OUTPUT);
pinMode( switchPin , INPUT_PULLUP); // sets pin as input
Particle.variable("force", &fsrReading, INT);
}
void loop()
{
int buttonState = digitalRead( switchPin );
// Use analogRead to read from the sensor
// This gives us a value from 0 to 4095
fsrReading = analogRead(fsrPin);
if(buttonState == HIGH){
digitalWrite( ledPin, LOW);
}
else if( buttonState == LOW & fsrReading >50 & fsrReading <= 1500 )
{
digitalWrite( ledPin, HIGH);
delay(1000);
digitalWrite( ledPin, LOW);
delay(1000);
}
else if (buttonState == LOW & fsrReading>1500 & fsrReading<=3000)
{
digitalWrite( ledPin, HIGH);
delay(500);
digitalWrite( ledPin, LOW);
delay(500);
}
else if (buttonState == LOW & fsrReading>3000)
{
digitalWrite( ledPin, HIGH);
delay(100);
digitalWrite( ledPin, LOW);
delay(100);
}
}
Click to Expand
Content Rating
Is this a good/useful/informative piece of content to include in the project? Have your say!
You must login before you can post a comment. .