/**
Mini piano for Arduino.
You can control the colorful buttons with your keyboard:
After starting the simulation, click anywhere in the diagram to focus it.
Then press any key between 1 and 8 to play the piano (1 is the lowest note,
8 is the highest).
Copyright (C) 2021, Uri Shaked. Released under the MIT License.
*/
const uint8_t buttonPins[] = { 12, 11, 10, 9, 7, 6, 5, 4 };
void setup() {
for (uint8_t i = 0; i < 8; i++) {
pinMode(buttonPins[i], INPUT_PULLUP);
}
Serial.begin(9600);
}
void loop() {
int pitch = 0;
for (uint8_t i = 0; i < 8; i++) {
if (digitalRead(buttonPins[i]) == LOW) {
pitch = i;
}
}
if (pitch) {
Serial.println(i);
}