/* Clavier_Piano transformation d'un clavier en piano par semageek.com */ #include #include // Pin du clavier const int DataPin = 2; const int IRQpin = 3; Tone freq1; const int NOTE_freq[] = { 261, 293, 329, 349, 392, 440, 494, 523 }; // DO, RE, MI, FA, SOL, LA, SI PS2Keyboard keyboard; void setup() { delay(1000); keyboard.begin(DataPin, IRQpin); Serial.begin(9600); //pin du haut-parleur freq1.begin(11); } void loop() { if (keyboard.available()) { // read the next key char c = keyboard.read(); // check for some of the special keys if (c == PS2_ENTER) { Serial.println(); } else if (c == PS2_TAB) { Serial.print("[Tab]"); } else if (c == PS2_ESC) { Serial.print("[ESC]"); } else if (c == PS2_PAGEDOWN) { Serial.print("[PgDn]"); } else if (c == PS2_PAGEUP) { Serial.print("[PgUp]"); } else if (c == PS2_LEFTARROW) { Serial.print("[Left]"); } else if (c == PS2_RIGHTARROW) { Serial.print("[Right]"); } else if (c == PS2_UPARROW) { Serial.print("[Up]"); } else if (c == PS2_DOWNARROW) { Serial.print("[Down]"); } else if (c == PS2_DELETE) { Serial.print("[Del]"); } else { // otherwise, just print all normal characters Serial.print(c); if (c=='a') { freq1.play( NOTE_freq[0], 100); } if (c=='s') { freq1.play( NOTE_freq[1], 100); } if (c=='d') { freq1.play( NOTE_freq[2], 100); } if (c=='f') { freq1.play( NOTE_freq[3], 100); } if (c=='g') { freq1.play( NOTE_freq[4], 100); } if (c=='h') { freq1.play( NOTE_freq[5], 100); } if (c=='j') { freq1.play( NOTE_freq[6], 100); } if (c=='k') { freq1.play( NOTE_freq[7], 100); } } } }