Created
February 17, 2013 17:33
-
-
Save Simon-L/4972421 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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