For my internet of things project, I wanted to make a music game using buttons and a speaker. The idea of the game is to repeat the notes using the buttons. Everytime you get it right, it adds another note that you must repeat. The game exercises your memory and pitch training.
int buttons[6]; //buttons[0] = 2; int notes[] = {262,294,330,349}; void setup() { // put your setup code here, to run once: Serial.begin(9600); buttons[0] = 6; buttons[1] = 7; } void loop() { // put your main code here, to run repeatedly: int keyVal = analogRead(A0); Serial.println(keyVal); if(keyVal >= 801){ tone(8, notes[0]); delay(50); } else if(keyVal >= 601 && keyVal <= 800){ tone(8, notes[1]); delay(50); } else if(keyVal >= 201 && keyVal <= 600){ tone(8, notes[2]); delay(50); } else if(keyVal >= 100 && keyVal <= 200){ tone(8, notes[3]); delay(50); } else{ noTone(8); } }
The game is very code heavy. I worked a long time trying to get the random number generator to work to generate a new note. My next step would be to make the game loop. Hopefully when I get another chance (and get better at C++) I will be able to finish this project.