User:Laurier Rochon/prototyping/clapping music button: Difference between revisions
(Created page with "<source lang="C"> //pattern String pat = "XXX XX X XX "; //pin for button const int buttonPin = 9; //original button state int buttonState = 0; void setup() { //setup mode fo...") |
No edit summary |
||
Line 1: | Line 1: | ||
This is going to need a bit more wiring with a button and resistor... | |||
<source lang="C"> | <source lang="C"> | ||
//pattern | //pattern |
Revision as of 15:47, 26 October 2010
This is going to need a bit more wiring with a button and resistor...
//pattern
String pat = "XXX XX X XX ";
//pin for button
const int buttonPin = 9;
//original button state
int buttonState = 0;
void setup() {
//setup mode for button
pinMode(buttonPin, INPUT);
}
void loop() {
//get the button state
buttonState = digitalRead(buttonPin);
//if it's pushed
if (buttonState == HIGH) {
//get the length of the pattern
int patlen = pat.length();
//loop
for (int p=0; p<patlen; p++) {
//if there's a X, play
if(pat.charAt(p) == 'X'){
tone(8, 800, 10);
}
delay(150);
}
}
}