/* Pour télécharger le ficher pitches.h
https://drive.google.com/file/d/0B3uxfp2Hl_RXVzFydWZrSjJ0bDg/view?usp=sharing&resourcekey=0-80XXqrJoeZZbEtR24HMKRQ
Cours d'initiation:
https://youtu.be/r5ZzGTsYlIo
*/
#include "pitches.h"
const int btnNotes[8] = {
NOTE_C4, NOTE_D4, NOTE_E4, NOTE_F4,
NOTE_G4, NOTE_A4, NOTE_B4, NOTE_C5
};
// btnPins[index] = { 0, 1, 2, 3, 4, 5, 6, 7};
const int btnPins[8] = {12, 11, 10, 9, 8, 7, 6, 5};
const int buzzer = 13;
void setup() { // Initialisation.
pinMode(buzzer, OUTPUT);
for (int index = 0; index < 8; index++) {
pinMode(btnPins[index], INPUT_PULLUP);
}
}
void loop() {
int pitch = 0;
for (int i = 0; i < 8; i++) {
if (digitalRead(btnPins[i]) == LOW) {
pitch = btnNotes[i];
}
}
if (pitch) {
tone(buzzer, pitch);
} else {
noTone(buzzer);
}
}