#include <IRremote.h>
#include <IRremoteInt.h>// amount of the class that manages the receiver ir
#include <LiquidCrystal.h>// amount of the class that handles the display
LiquidCrystal LCD (12, 11, 5, 4, 3, 2); // create an object of Liquid Crystal class
Irpin int = 9; // Check the pin 13 to the infrared receiver
IRrecv irrecv (Irpin); // create an object of class IRrecv
decode_results results; // create an object to store the signals received by the receiver
const int contrastoPin = A0; // imposed a pin that will adjust the contrast.
mosfetGate const int = 13; // imposed a pin that will handle the voltage on the mosfet gate
piezoHigh const int = 10; // imposed pin which will sound the piezo with high notes
const int piezoLow = 6; // imposed pin which will sound the piezo with low notes
const int greenLED = 7; // imposed a pin that will handle the green led
const int RedLED = 8; // imposed a pin that will manage the red led
PowerSwitch int = 0; // create a "switch" variable that turns on / off the game
int m = 0; // variable that will host the first operand
int n = 0; // variable that will host the second operand
int answer = 0; // variable that will host the user's response
rispostaEsatta int = 0; // imposed a variable to contain the correct answer to questions
operation int = 0; // variable that contains the value associated with each task
difficulty int = 0; // variable that will host the difficulty User
contrast int = 15; // choose the contrast value.
int score = 0; // variable that holds the player's score
void setup ()
{
pinMode (contrastoPin, OUTPUT);
pinMode (mosfetGate, OUTPUT);
pinMode (greenLED, OUTPUT);
pinMode (RedLED, OUTPUT);
pinMode (piezoHigh, OUTPUT);
analogWrite (contrastoPin, contrast);
digitalWrite (mosfetGate , HIGH);
digitalWrite (RedLED, HIGH);
digitalWrite (greenLED, HIGH);
delay (1000);
digitalWrite (mosfetGate, LOW);
digitalWrite (RedLED, LOW);
digitalWrite (greenLED, LOW);
irrecv.enableIRIn (); // Start the receiver
lcd.begin (16, 2); // Start the display giving the size (2 lines, 16 characters)
randomSeed (analogRead (3));
Serial.begin (9600);
}
void loop ()
{
if (PowerSwitch == 0) {
digitalWrite (mosfetGate, LOW);
if (irrecv.decode (& results)) {
if (results.value == 16753245) {
Serial.println (results.value);
PowerSwitch = 1;
digitalWrite (mosfetGate, HIGH);
lcd.print ( "Welcome");
lcd.setCursor (0, 1);
lcd.print ( "math game");
delay (2000);
lcd.clear ();
lcd.setCursor (0, 0);
lcd.print ( "Set");
lcd.setCursor (0.1);
lcd.print ( "Difficulty' 1-5 ");
irrecv.resume (); // wait for the next value entered
while (results.value == 16753245) {
if (irrecv.decode (& results)) {
switch (results.value) {
16753245 houses: PowerSwitch = 0;
results.value = 0;
lcd.clear ();
lcd.setCursor (0,0);
lcd.print ( "Goodbye");
lcd.setCursor (0.1);
lcd.print ( "by Zamein");
delay (3000);
lcd.clear () ;
lcd.setCursor (0,0);
irrecv.resume ();
break;
16,724,175 homes: difficulty = 1;
lcd.clear ();
lcd.setCursor (0, 0);
lcd.print ( 'Difficulty');
lcd.setCursor (0, 1);
lcd.print (difficulty);
delay (1000);
break;
16,718,055 homes: difficulty = 2;
lcd.clear ();
lcd.setCursor (0, 0);
lcd.print ( " Difficulty: ");
lcd.setCursor (0, 1);
lcd.print (difficulty);
delay (1000);
break;
16,743,045 homes: difficulty = 3;
lcd.clear ();
lcd.setCursor (0, 0);
lcd.print ( 'Difficulty');
lcd.setCursor (0, 1);
lcd.print (difficulty);
delay (1000);
break;
16,716,015 homes: difficulty = 4;
lcd.clear ();
lcd.setCursor ( 0, 0);
lcd.print ( 'Difficulty');
lcd.setCursor (0, 1);
lcd.print (difficulty);
delay (1000);
break;
16,726,215 homes: difficulty = 5;
lcd.clear () ;
lcd.setCursor (0, 0);
lcd.print ( 'Difficulty');
lcd.setCursor (0, 1);
lcd.print (difficulty);
delay (1000);
break;
default: results.value = 16753245 ;
}
}
delay (10);
}
}
}
}
Else {
irrecv.resume (); // put listening the sensor
switch (difficulty) {
case 1: m = random (1, 10);
n = random (1, 10);
action = random (0,2);
break;
case 2: m = random (1, 25);
n = random (1, 25);
action = random (0,2);
break;
case 3: m = random (1, 50);
n = random (1, 50);
action = random (0.2);
break;
case 4: m = random (1, 100);
n = random (1, 100);
action = random (0,2);
break;
case 5: m = random (1, 150 );
n = random (1, 150);
action = random (0,2);
break;
}
lcd.clear ();
lcd.setCursor (0,0);
if (action == 0) {
lcd.print ( m);
lcd.print ( "+");
lcd.print (n);
lcd.print ( "=?");
}
else {
lcd.print (m);
lcd.print ( "*");
lcd. print (n);
lcd.print ( "=?");
}
lcd.setCursor (0.1);
while (results.value! = 16,769,565) {
if (irrecv.decode (& results)) {
switch (results.value) {
16753245 houses: PowerSwitch = 0;
results.value = 16769565;
score = 0;
lcd.clear ();
lcd.setCursor (0,0);
lcd.print ( "Goodbye");
lcd. setCursor (0.1);
lcd.print ( "by Zamein");
delay (3000);
lcd.clear ();
irrecv.resume ();
break;
16,736,925 homes: answer = 0;
lcd.setCursor (0.1 );
lcd.print ( "");
lcd.setCursor (0.1);
break;
16,738,455 homes: response response = * 10;
if (answer> 0) {
lcd.print ( "0");
}
break;
case 16724175: response response = * 10;
answer = answer + 1;
lcd.print ( "1");
break;
16,718,055 homes: response = response * 10;
answer = answer + 2;
lcd.print ( "2");
break ;
16743045 houses: response response = * 10;
response = response + 3;
lcd.print ( "3");
break;
16,716,015 homes: response response = * 10;
response = response + 4;
lcd.print ( "4") ;
break;
case 16726215: response response = * 10;
answer = answer + 5;
lcd.print ( "5");
break;
16,734,885 homes: response response = * 10;
answer = answer + 6;
lcd.print ( "6 ");
break;
case 16728765: response response = * 10;
answer = answer + 7;
lcd.print (" 7 ");
break;
16,730,805 homes: response response = * 10;
response = response + 8;
lcd.print ( "8");
break;
16,732,845 homes: response response = * 10;
answer = answer + 9;
lcd.print ( "9"); ;
Break;
}
irrecv.resume ();
}
}
if (PowerSwitch! = 0) {
if (action == 0) {
rispostaEsatta = m + n;
}
else {
rispostaEsatta = m * n;
}
lcd.clear ();
lcd.setCursor (0,0);
if (response == rispostaEsatta) {
lcd.print ( "Correct answer");
score = score + (10 * difficulty);
lcd.setCursor (0.1 );
lcd.print (score);
lcd.print ( "points");
digitalWrite (greenLED, HIGH);
analogWrite (piezoLow, 500);
delay (250);
analogWrite (piezoLow, 200);
}
else {
lcd.print ( "wrong answer");
score = 0;
lcd.setCursor (0.1);
lcd.print (score);
lcd.print ( "points");
digitalWrite (RedLED, HIGH);
analogWrite (piezoLow, 250);
delay (250);
analogWrite (piezoHigh, 250);
}
delay (500);
digitalWrite (greenLED, LOW);
digitalWrite (RedLED, LOW);
digitalWrite (piezoHigh, LOW);
digitalWrite (piezoLow, LOW);
lcd.clear ( );
results.value = 0;
answer = 0;
}
}
}
And i'm getting a lot of errors.
piz help thx you
FYI I do not take credit for this project.
