Skip to content

Instantly share code, notes, and snippets.

@christiangenco
Created October 28, 2014 16:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christiangenco/9b0b2232e9ccb2f532d7 to your computer and use it in GitHub Desktop.
Save christiangenco/9b0b2232e9ccb2f532d7 to your computer and use it in GitHub Desktop.
An IO device for your feet: http://christian.gen.co/walkie-sockie/
// WalkieSockie
// Christian Genco: @cgenco
// An alternate input/output device for the feet
// pins
static int pressurePin = A5, vibratorPin = 11;
// thresholds
static int pressureLow = 0, pressureHigh = 1000,
vibeLow = 0, vibeHigh = 255;
boolean smooth = true;
static int threshold = pressureHigh/2;
void setup() {
vibratorPin = 9;
pinMode(pressurePin, INPUT);
pinMode(vibratorPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
int sensorValue = analogRead(pressurePin);
if(smooth){
analogWrite(vibratorPin, map(sensorValue, pressureLow, pressureHigh, vibeLow, vibeHigh));
}else{
boolean crossedThreshold = sensorValue > threshold;
digitalWrite(vibratorPin, crossedThreshold ? 1 : 0);
}
Serial.println(sensorValue);
// Serial.println(map(sensorValue, pressureLow, pressureHigh, 0, 255));
// Serial.println(sensorValue);
delay(100); // delay in between reads for stability
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment