#include "pitches.h"
/* Constants - define pin numbers for LEDs,
buttons and speaker, and also the game tones: */
const byte ledPins[] = {9, 10, 11, 12};
const byte buttonPins[] = {2, 3, 4, 5};
#define SPEAKER_PIN 8
#define MAX_GAME_LENGTH 100
const int gameTones[] = { NOTE_G3, NOTE_C4, NOTE_E4, NOTE_G5};
int RandomNumbers;
byte i;
int count;
void setup() {
Serial.begin(9600);
pinMode(ledPins[0], OUTPUT);
pinMode(buttonPins[0], INPUT);//yellow
pinMode(buttonPins[1], INPUT);//blue
pinMode(buttonPins[2], INPUT);//green
pinMode(SPEAKER_PIN, OUTPUT);
randomSeed(analogRead(A0));
playagain();
}
void countChoosing(){
int btn_minus=digitalRead(buttonPins[0]);
int btn_add=digitalRead(buttonPins[1]);
if(btn_add==HIGH){
count++;
Serial.print(count);
// Serial.print("blue");
delay(1000);
}else{
if(btn_minus==HIGH){
count--;
Serial.print(count);
delay(1000);
//Serial.print("yellow");
}
}
}
void loop() {
int btn_check=digitalRead(buttonPins[2]);
countChoosing();
}
void gameOver() {
Serial.print("Game over! your score: ");
delay(200);
// Play a Wah-Wah-Wah-Wah sound
tone(SPEAKER_PIN, NOTE_DS5);
delay(300);
tone(SPEAKER_PIN, NOTE_D5);
delay(300);
tone(SPEAKER_PIN, NOTE_CS5);
delay(300);
for (byte i = 0; i < 10; i++) {
for (int pitch = -10; pitch <= 10; pitch++) {
tone(SPEAKER_PIN, NOTE_C5 + pitch);
delay(5);
}
}
noTone(SPEAKER_PIN);
delay(500);
}
void playLevelUpSound() {
tone(SPEAKER_PIN, NOTE_E4);
delay(150);
tone(SPEAKER_PIN, NOTE_G4);
delay(150);
tone(SPEAKER_PIN, NOTE_E5);
delay(150);
tone(SPEAKER_PIN, NOTE_C5);
delay(150);
tone(SPEAKER_PIN, NOTE_D5);
delay(150);
tone(SPEAKER_PIN, NOTE_G5);
delay(150);
noTone(SPEAKER_PIN);
}
void playagain(){
RandomNumbers=random(1,11);
Serial.println(RandomNumbers);
delay(500);
}
void checkthenumber(int x, int y){
if(x==y){
playLevelUpSound();
}else{
gameOver();
}
}