/**
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.
*/
enum Modes
{
mode01,
mode02,
mode03,
mode04,
mode05,
mode06,
mode07,
mode08,
};
const int nbrModes = 8;
String rollfail = "Hello String";
int roll = 0;
int button1 = 5;
int button2 = 6;
int button3 = 7;
int button4 = 8;
int button5 = 9;
int button6 = 10;
int button7 = 11;
int button8 = 12;
int buttonstate1 = 0;
int buttonstate2 = 0;
int buttonstate3 = 0;
int buttonstate4 = 0;
int buttonstate5 = 0;
int buttonstate6 = 0;
int buttonstate7 = 0;
int buttonstate8 = 0;
void setup() {
Serial.begin(9600);
Serial.println("go");
pinMode(button1, INPUT_PULLUP);
pinMode(button2, INPUT_PULLUP);
pinMode(button3, INPUT_PULLUP);
pinMode(button4, INPUT_PULLUP);
pinMode(button5, INPUT_PULLUP);
pinMode(button6, INPUT_PULLUP);
pinMode(button7, INPUT_PULLUP);
pinMode(button8, INPUT_PULLUP);
}
void loop()
{
buttonstate1 = digitalRead(button1);
buttonstate2 = digitalRead(button2);
buttonstate3 = digitalRead(button3);
buttonstate4 = digitalRead(button4);
buttonstate5 = digitalRead(button5);
buttonstate6 = digitalRead(button6);
buttonstate7 = digitalRead(button7);
buttonstate8 = digitalRead(button8);
//Serial.println (buttonstate1);
displayRandomScreenMode();
Serial.print(buttonstate1);
Serial.print(buttonstate2);
Serial.print(buttonstate3);
Serial.print(buttonstate4);
Serial.print(buttonstate5);
Serial.print(buttonstate6);
Serial.print(buttonstate7);
Serial.println(buttonstate8);
}
void displayRandomScreenMode()
{
int mode = getRandomMode();
switch (mode)
{
// case noise:
// displayNoisePixelated(random(10, 300), false, random(10, 2000));
// break;
case mode01:
Serial.println("mode01");
delay(500);
break;
case mode02:
Serial.println("mode02");
delay(500);
break;
case mode03:
Serial.println("mode03");
delay(500);
break;
case mode04:
Serial.println("mode04");
delay(500);
break;
case mode05:
Serial.println("mode05");
delay(500);
break;
case mode06:
Serial.println("mode06");
delay(500);
break;
case mode07:
Serial.println("mode07");
delay(500);
break;
case mode08:
Serial.println("mode08");
delay(500);
break;
}
}
int getRandomMode()
{
// return random(nbrModes);
//return number 1-nbrModes
//Serial.println(randomchoice);
//int randomchoice ="null";
int randomchoice =random(nbrModes);
Serial.println(randomchoice);
if(randomchoice == 0 && buttonstate1 == 1){
Serial.println("mode01 roll and high");
return randomchoice;
}
else if(randomchoice == 1 && buttonstate2 == 1){
Serial.println("mode02 roll and high");
return randomchoice;
}
else if(randomchoice == 2 && buttonstate3 == 1){
Serial.println("mode03 roll and high");
return randomchoice;
}
else if(randomchoice == 3 && buttonstate4 == 1){
Serial.println("mode04 roll and high");
return randomchoice;
}
else if(randomchoice == 4 && buttonstate5 == 1){
Serial.println("mode05 roll and high");
return randomchoice;
}
else if(randomchoice == 5 && buttonstate6 == 1){
Serial.println("mode06 roll and high");
return randomchoice;
}
else if(randomchoice == 6 && buttonstate7 == 1){
Serial.println("mode07 roll and high");
return randomchoice;
}
else if(randomchoice == 7 && buttonstate8 == 1){
Serial.println("mode08 roll and high");
return randomchoice;
}
else if(roll >= 10){
roll = 0;
Serial.println ("Too many fails, sending 0");
return 0;
}
else {
roll++;
Serial.print("Rolled ");
Serial.print(randomchoice);
Serial.print(", rerolling. Roll# ");
Serial.println(roll);
randomchoice =random(nbrModes);
}
}
// concatenating two strings:
//stringOne = String(stringTwo + " with more");
// prints "This is a string with more":
//Serial.println(stringOne);
//int randomchoice =random(nbrModes);
//Serial.println(nbrModes);
//String readrandom = 'buttonstate' + randomchoice;
//Serial.println(readrandom);
//If (readrandom == LOW);
//int sensorValue = analogRead(A0);
//String stringOne = "Sensor value: ";
//String stringThree = stringOne + sensorValue;
//Serial.println(stringThree);
// for (int dogs_feet=0 ; dogs_feet <nbrModes;dogs_feet++ )
// {
// switch_val[dogs_feet]=digitalRead(switch_pin[dogs_feet]);
// }
// int the_random = random(nbrModes);
// int retries = 10;
//while (switch_val[the_random]==1 && retries >0)
//{
// the_random = random(nbrModes);
// retries--;
//}
//if (retries == 0) the_random = random(nbrModes);