int randomNumber;
int randomNumberTWO;
int randomResultNumb;
const int buttonPinMULT = 2; // the number of the pushbutton pin
int buttonStateMULT = 0; // variable for reading the pushbutton status
const int buttonPinADD = 3; // the number of the pushbutton pin
int buttonStateADD = 0; // variable for reading the pushbutton status
const int buttonPinSUB = 4; // the number of the pushbutton pin
int buttonStateSUB = 0; // variable for reading the pushbutton status
// START custom fuctions ection --------------------------- <
int multFunction (int numOne, int numTwo)
{
int result = numOne * numTwo;
return result;
}
int addFunction (int numOne, int numTwo)
{
int result = numOne + numTwo;
return result;
}
int subFunction (int numOne, int numTwo)
{
int result = numOne - numTwo;
return result;
}
// END custom fuctions ection --------------------------- <
void setup()
{
Serial.begin(9600);
//button setup
pinMode(buttonPinMULT, INPUT);
pinMode(buttonPinADD, INPUT);
pinMode(buttonPinSUB, INPUT);
//Random number generator
randomSeed(analogRead(0));
randomNumber = random(2, 4);
randomNumberTWO = random(1, 10);
delay(10);
}
void loop()
{
buttonStateMULT = digitalRead(buttonPinMULT);
buttonStateADD = digitalRead(buttonPinADD);
buttonStateSUB = digitalRead(buttonPinSUB);
if (buttonStateMULT == HIGH)
{
// Multiplication
int mult = multFunction (randomNumber,randomNumberTWO);
Serial.println("Multiplication : " +
String(randomNumber) +'x' + String(randomNumberTWO) + '=' + String(mult));
}
else if(buttonStateADD == HIGH)
{
// Addition
int add = addFunction (randomNumber,randomNumberTWO);
Serial.println("Addition : " +
String(randomNumber) +'+' + String(randomNumberTWO) + '=' + String(add));
}
else if(buttonStateSUB == HIGH)
{
// Subtraction
int sub = subFunction (randomNumber,randomNumberTWO);
Serial.println("Subtraction: " +
String(randomNumber) +'-' + String(randomNumberTWO) + '=' + String(sub));
}
}