Skip to content

Instantly share code, notes, and snippets.

@ErikABengtsson
Last active April 13, 2017 05:22
Show Gist options
  • Save ErikABengtsson/de6c68b1874fd726092122ea362e1b15 to your computer and use it in GitHub Desktop.
Save ErikABengtsson/de6c68b1874fd726092122ea362e1b15 to your computer and use it in GitHub Desktop.
/*
Trigger Guard
Erik Bengtsson
GDES-3015-001 Wearable Computing
OCAD University
Created on 6th April 2017
Based on:
FSR testing sketch, Adafruit, https://learn.adafruit.com/force-sensitive-resistor-fsr/using-an-fsr
Button Example, DojoDave
*/
int fsrAnalogPin = 0; // FSR is connected to analog 0
int LEDpin = 11; // LED is connected to pin 11
int fsrReading; // The analog reading from the FSR resistor divider
void setup(void) {
Serial.begin(9600); // Sending debugging information via the serial monitor
pinMode(LEDpin, OUTPUT);
}
void loop(void) {
fsrReading = analogRead(fsrAnalogPin);
Serial.print("Analog reading = ");
Serial.println(fsrReading);
delay(100);
if (fsrReading > 20 && fsrReading < 700) { // Using threshholds to set the range for lighting up the LED
digitalWrite(LEDpin, HIGH); //LED on
Serial.println(" - Medium squeeze");
} else {
digitalWrite(LEDpin, LOW); //LED off
Serial.println(" - Big squeeze");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment