#define CN4 262
#define CS4 277
#define DN4 294
#define DS4 311
#define EN4 330
#define FN4 349
#define FS4 370
#define GN4 392
#define GS4 415
#define AN4 440
#define AS4 466
#define BN4 494
#define BEEP_PIN 10
const byte buttonPin[] = {2, 3, 4, 5};
const byte ledPin[] = {6, 7, 8, 9};
const int note[] = {GN4, CN4, EN4, AN4};
const int duration = 250;
int number, sequence[5];
void setup() {
Serial.begin(115200);
randomSeed(analogRead(A0));
for (byte i = 0; i < 4; i++) { // configure pins
pinMode(buttonPin[i], INPUT_PULLUP);
pinMode(ledPin[i], OUTPUT);
pinMode(BEEP_PIN, OUTPUT);
}
Serial.print("Press 1 to start.");
while (digitalRead(buttonPin[0])) {}; // wait for button press.
}
void loop() {
sequence[number] = random(4);
for (int i = 0; i < 4; i++) {
if (digitalRead(buttonPin[number]) == LOW)
showsequence();
Serial.print(buttonPin[number]);
}
}
void showsequence() {
digitalWrite(ledPin[sequence[number]], HIGH);
tone (BEEP_PIN, note[number], duration);
delay(duration);
noTone(BEEP_PIN);
}