Skip to content

Instantly share code, notes, and snippets.

@rakasaka
Created September 6, 2011 23:12
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 rakasaka/1199266 to your computer and use it in GitHub Desktop.
Save rakasaka/1199266 to your computer and use it in GitHub Desktop.
Musical stairs sensor code for Arduino
#include <HashMap.h>
int mini = 0;
int maxi = 16;
const byte HASH_SIZE = 16;
HashType<int,int> hashRawArray[HASH_SIZE];
HashMap<int,int> hashMap = HashMap<int,int>( hashRawArray , HASH_SIZE );
void setup(){
Serial.print("reset");
Serial.begin(9600);
}
void loop(){
for (int thisPin = mini; thisPin < maxi; thisPin++) {
int val = analogRead(thisPin);
if (val > 200){
int curHit = hashMap.getValueOf(thisPin);
if ((curHit+1) > 3) {
hashMap[thisPin](thisPin,0);
Serial.print("#");
Serial.print(thisPin);
Serial.print("#");
}
else {
hashMap[thisPin](thisPin,curHit+1);
}
}
else {
hashMap[thisPin](thisPin,0);
}
delay(5);
}
Serial.println();
}
@pg
Copy link

pg commented Sep 21, 2011

Any chance that this might get comments added down the road? I'm wondering why you wait until the curHit value gets above 3. Is it to rule out noise/interference?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment