User login

Powered by Drupal, an open source content management system

Theory and Practice of Tangible User Interfaces

Lab 5: All in One - The Grip Stick

Submitted by ashley on Wed, 10/08/2008 - 23:56

 

/*
 * The grip stick is a device that measures how much pressure someone's grip is exerting on the stick. If it falls into the correct range, the led turns on.
* I would use this device when I coach squash to teach people how hard they should be gripping the racquet
 */
int sensorPin = 0;  // select the input pin for the sensor
int ledPin = 11;    // select the output pin for the LED
int val = 0;        // variable to store the value coming from the sensor
void setup() {
  Serial.begin(9600);
}
void loop() {
  val = analogRead(sensorPin); // read the value from the sensor, 0-1023
  if (val > 570 && val < 840) {
    analogWrite(ledPin, val);
  } else {
    analogWrite(ledPin, 0);   
  } // analogWrite (dimming the LED) can be between 0-255
  Serial.println(val);       // writing the value to the PC via serial connection 
  delay(5);                   // rest a little...
}