« Arduino: i can haz knight riders! | Home | Web links for January 29th »
Arduino: 4 button piezo synth (failed)
By booyaa | January 29, 2008
I had to give up on this project, I could get the LEDs to light up, but the most I could get out of the piezo speaker was faint clicks…
The piezo was working cause this bit of code worked when it was just rigged up to power and the output pin.
/*
Author: booyaa (booyaa.org)
Changelog
20080128 - tidied up code to prep for noise making!
*/
int speakerOut = 9;
int val = 0;
int i = 0; // was 4
int maxInputs = 7;
int buttons[] = { 4, 5 ,6, 7 };
int tones[] = { 3830, 3400, 3038, 2864 };
int count = 0;
void setup() {
for( i=4; i<=maxInputs; i++) {
pinMode( i, INPUT );
}
pinMode(speakerOut, OUTPUT);
Serial.begin( 9600 );
}
void loop() {
for( i=4; i<=maxInputs; i++) {
val = digitalRead( i );
for ( count=4; count <= maxInputs; count++ ) {
if ( val == 0 && i == count ) {
Serial.print( "button = " );
Serial.print( i );
Serial.print( " val = " );
Serial.print( val );
Serial.print( " count = " );
Serial.println( count );
// this is where the music code will go, which comes from this sketch
// http://www.arduino.cc/en/Tutotial/KeyboardSerial
digitalWrite(speakerOut, HIGH);
delayMicroseconds(tones[count]);
digitalWrite(speakerOut, LOW);
delayMicroseconds(tones[count]);
}
}
}
delay (500);
}
Topics: Uncategorized |

Blog