topical media & game development
graphic-processing-algorithm-Ch11-p291-p291.pde / pde
// do , re , mi , fa , sol , la , si , do
int freqs[] = {
1915, 1700, 1519, 1432, 1275, 1136, 1014, 956};
void setup(){
pinMode(11,OUTPUT);
Serial.begin(9600); //open the serial to print
}
void loop(){
int val = Serial.read(); //read the serial to see
if(val>0 && val <= 9){ //which key was pressed
val = val - 0; //convert the character to an integer
Serial.print(val,DEC);
Serial.println();
for(int i=0; i<500; i++){ //duration of the tone (.5 seconds)
digitalWrite(11,HIGH);
delayMicroseconds(freqs[val]); //the tones frequency
digitalWrite(11,LOW);
delayMicroseconds(freqs[val]);
}
}
}
(C) Æliens
04/09/2009
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.