Skip to content

Instantly share code, notes, and snippets.

@Simon-L
Created February 17, 2013 17:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save Simon-L/4972421 to your computer and use it in GitHub Desktop.
Save Simon-L/4972421 to your computer and use it in GitHub Desktop.
// Range : 170 - 1015
int range = 1015 - 170;
boolean state = false;
void setup() {
Serial.begin(9600);
pinMode(13, OUTPUT);
}
void loop() {
int capVal = analogRead(A0);
if ( (state == false) && (capVal <= 1015) ) {
if (capVal <= 170) {
int velocity = 127;
Serial.print("Hit with velocity: ");
Serial.print(velocity);
Serial.print(" (");
Serial.print( capVal );
Serial.println(") ");
state = true;
}
else {
int velocity = ((float)(1015 - capVal)/range)*127;
Serial.print("Hit with velocity: ");
Serial.print( velocity );
Serial.print(" ( ");
Serial.print( capVal );
Serial.print(" ) ");
//Serial.println(velocity);
state = true;
}
}
else if ((capVal > 1015) && (state == true)) {
Serial.print("Button released ");
Serial.print(" ( " );
Serial.print( capVal );
Serial.println( " )" );
state = false;
}
else {
// Rien c'est cool lol
digitalWrite(13, HIGH);
}
//delay(100);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment