Create a gist now

Instantly share code, notes, and snippets.

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