Hi everyone. I am new to Arduino. I have two problem. First, I have a program in c++ language and I have some problem to convert it to Arduino programming (in C++ we use “cin” to ask user to enter answer but how about in Arduino?). Should anybody give me some guide and suggestion…I am using Arduino Uno and keypad 16 button.
second, Any idea to make a complete circuit that connect Keypad 16 button and Arduino. I already google about it but still have no solution.
Here some of C++ program and Arduino that I already try…
Thanks a lot for any help.
int main()
{
int sum;
int answer;
int correct = 0;
int wrong = 0;
int menu;
int i;
int j;
srand(time(0));
do {
cout << setw( 50 ) << "Kids Math Quiz Game!!!" << endl;
cout << setw( 49 ) << "**********Menu**********" << endl;
cout << setw( 44 ) << "[1] Addition " << endl;
cout << setw( 47 ) << "[2] Subtraction " << endl;
cout << setw( 40 ) << "[3] Exit " << endl << endl;
cout <<"Please enter your choice: ";
cin >> menu;
switch ( menu )
{
case 1:
i = rand()%10;
j = rand()%10;
if ((i<=1 && j<=9) || (i<=9 && j<=1))
{
cout << "What is " << i << " + " << j << " = ";
cin >> answer;
sum = i + j;
if( answer == sum )
{
cout <<"Great Job!!!!!" << endl << endl;
correct++;
}
else
{
cout << "Sorry " << i <<" + " << j << " = " << sum <<endl << endl;
wrong++;
}
cout << "You got " << correct <<" right and " << wrong << " wrong"<< endl<< endl;
cin.get();
}
#include <Keypad.h>
int sum;
int answer;
int correct = 0;
int wrong = 0;
int menu;
//int i;
//int j;
//long randNumber;
long i;
long j;
const byte ROWS = 4; // four rows
const byte COLS = 4; // four columns
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'#','0','*','D'}
};
byte rowPins[ROWS] = {8,1,2,4}; // Connect to the row pinouts of the keypad
byte colPins[COLS] = {3,5,6,7}; // Connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
byte ledPin = 13;
boolean blink = false;
void setup()
{
Serial.begin(9600); // Set up Serial library at 9600 bps
pinMode(ledPin, OUTPUT); // Sets the digital pin as output
digitalWrite(ledPin, HIGH); // Sets the LED on
keypad.addEventListener(keypadEvent); // Add an event listener for the keypad
}
void loop()
{
char key = keypad.getKey();
if (key != NO_KEY)
{
Serial.println(key);
}
if (blink)
{
digitalWrite(ledPin,!digitalRead(ledPin));
delay(100);
}
}
void keypadEvent(KeypadEvent key)
{
//Serial.println(randomNumber);
Serial.println(" **KIDS MATH");
Serial.println(" QUIZ GAME!**");
Serial.println("******MENU******");
Serial.println("[1] Addition");
Serial.println("[2] Subtraction");
Serial.println("[3] Exit");
Serial.println("Enter Your Choice: ");
switch (key)
{
case '1':
i = random(10);
j = random(10);
if ((i<=1 && j<=9) || (i<=9 && j<=1))
{
Serial.println("What is ");
Serial.print(i);
Serial.print(" + ");
Serial.print(j);
Serial.print(" = ");
Serial.println(i + j);
}
Thanks