I'm confused as to what the problem is, it gives me an invalid header file error the moment I put Wire.begin(); in the setup
#include <LiquidCrystal.h>
#include <IRremote.h>
#include <Wire.h>
#define IR_RECEIVE_PIN 7
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
struct easyQuestions {
String prompt;
String answer;
char removedLetters[2];
int removedIndices[2];
};
struct mediumQuestions {
String prompt;
String answer;
char removedLetters[3];
int removedIndices[3];
};
easyQuestions easyquestions[10];
mediumQuestions mediumquestions[10];
char sprite = 'o';
int xval = 0;
int yval = 0;
int value;
int difficulty = 1;
bool difficultySet = false;
bool gameStarted = false;
int questionNumber = 0;
int score = 0;
char letter;
bool questionPresented = false;
int missingLetters = 0;
byte x = 0;
bool hearts = false;
int heartcount = 3;
void setupQuestions() {
easyquestions[0].prompt = "US capital?";
easyquestions[0].answer = "WAS_INGT_N";
easyquestions[0].removedLetters[0] = 'H';
easyquestions[0].removedLetters[1] = 'O';
easyquestions[0].removedIndices[0] = 3; // Reduced by 1
easyquestions[0].removedIndices[1] = 8; // Reduced by 1
easyquestions[1].prompt = "Canada capital?";
easyquestions[1].answer = "_ELH_";
easyquestions[1].removedLetters[0] = 'D';
easyquestions[1].removedLetters[1] = 'I';
easyquestions[1].removedIndices[0] = 0; // Reduced by 1
easyquestions[1].removedIndices[1] = 4; // Reduced by 1
easyquestions[2].prompt = "France capital?";
easyquestions[2].answer = "_ARI_";
easyquestions[2].removedLetters[0] = 'S';
easyquestions[2].removedLetters[1] = 'P';
easyquestions[2].removedIndices[0] = 0; // Reduced by 1
easyquestions[2].removedIndices[1] = 4; // Reduced by 1
easyquestions[3].prompt = "Russia capital?";
easyquestions[3].answer = "M_SCO_";
easyquestions[3].removedLetters[0] = 'O';
easyquestions[3].removedLetters[1] = 'W';
easyquestions[3].removedIndices[0] = 1; // Reduced by 1
easyquestions[3].removedIndices[1] = 5; // Reduced by 1
easyquestions[4].prompt = "Italy capital?";
easyquestions[4].answer = "_O_E";
easyquestions[4].removedLetters[0] = 'R';
easyquestions[4].removedLetters[1] = 'M';
easyquestions[4].removedIndices[0] = 0; // Reduced by 1
easyquestions[4].removedIndices[1] = 2; // Reduced by 1
easyquestions[5].prompt = "Spain capital?";
easyquestions[5].answer = "M_D_ID";
easyquestions[5].removedLetters[0] = 'A';
easyquestions[5].removedLetters[1] = 'R';
easyquestions[5].removedIndices[0] = 1; // Reduced by 1
easyquestions[5].removedIndices[1] = 3; // Reduced by 1
easyquestions[6].prompt = "China capital?";
easyquestions[6].answer = "BE_IN_";
easyquestions[6].removedLetters[0] = 'I';
easyquestions[6].removedLetters[1] = 'J';
easyquestions[6].removedIndices[0] = 2;
easyquestions[6].removedIndices[1] = 5;
easyquestions[7].prompt = "Japan capital?";
easyquestions[7].answer = "TO__O";
easyquestions[7].removedLetters[0] = 'K';
easyquestions[7].removedLetters[1] = 'Y';
easyquestions[7].removedIndices[0] = 2;
easyquestions[7].removedIndices[1] = 3;
easyquestions[8].prompt = "Australia capital?";
easyquestions[8].answer = "CANB_R_A";
easyquestions[8].removedLetters[0] = 'E';
easyquestions[8].removedLetters[1] = 'R';
easyquestions[8].removedIndices[0] = 4;
easyquestions[8].removedIndices[1] = 6;
//medium prompts should have something not related to capitals
}
void setup() {
lcd.begin(16, 2);
lcd.setCursor(3, 1);
IrReceiver.begin(IR_RECEIVE_PIN);
Serial.begin(9600);
randomSeed(0);
setupQuestions();
Wire.begin(4);
}
bool gameEnded = false;
void loop() {
if (IrReceiver.decode()) {
IrReceiver.resume();
value = IrReceiver.decodedIRData.command;
}
lcd.clear();
lcd.setCursor(0, 0);
while (!difficultySet){
if (IrReceiver.decode()) {
IrReceiver.resume();
value = IrReceiver.decodedIRData.command;
}
lcd.print("Diff");
lcd.setCursor(0,1);
lcd.print("(1:E,2:M,3:H)");
if (value == 16){
difficulty = 1;
difficultySet = true;
Serial.println(difficulty);
}
else if (value == 17){
difficulty = 2;
difficultySet = true;
Serial.println(difficulty);
}
else if (value == 18){
difficulty = 3;
difficultySet = true;
Serial.println(difficulty);
}else{
difficulty = 1;
}
}
if (!hearts){
hearts = true;
heartcount = 3;
}
game(difficulty, value);
}
void game(int difficulty, int value) {
gameEnded = false;
if (difficulty == 1){
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(easyquestions[questionNumber].prompt);
delay(5000);
while (!gameEnded){
if (IrReceiver.decode()) {
IrReceiver.resume();
value = IrReceiver.decodedIRData.command;
}
while (!questionPresented){
printanswer(questionNumber, difficulty);
value = 0;
}
if (missingLetters == 2){
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Ur pretty good");
xval = 0;
questionNumber++;
questionPresented = false;
missingLetters = 0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(easyquestions[questionNumber].prompt);
delay(2500);
}
switch(value){
case 16:
if (xval != 16){
lcd.setCursor(xval,1);
lcd.print(" ");
xval++;
}else if (xval == 16){
lcd.setCursor(xval,1);
lcd.print(" ");
xval = 0;
}
lcd.setCursor(xval, 1);
lcd.print(sprite);
break;
case 17:
if (xval != 0){
lcd.setCursor(xval,1);
lcd.print(" ");
xval--;
}else if (xval == 0){
Serial.println("You cant go back further dawg");
}
lcd.setCursor(xval, 1);
lcd.print(sprite);
break;
case 18:
changeball(xval);
break;
case 20:
addletter(questionNumber, xval, sprite,2);
}
value = 0;
}
}
}
//changeball function
void changeball(int xval) {
while (true) {
Serial.println("Enter a letter to change the ball to");
while (Serial.available() == 0) {
// Wait for user input
}
// Read the user input
String userInput = Serial.readString();
// Check if the input is a single uppercase letter
if (userInput.length() == 1 && isUpperCase(userInput[0])) {
char letter = userInput[0];
// Print the letter on the LCD screen at the specified position
lcd.setCursor(xval, 1);
sprite = letter;
lcd.print(sprite);
break; // Exit the loop if a valid input is provided
} else {
Serial.println("Please enter a single uppercase letter");
}
}
}
void printanswer(int questionNumber, int difficulty){
if (difficulty == 1){
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(easyquestions[questionNumber].answer);
lcd.setCursor(0,1);
lcd.print(sprite);
questionPresented = true;
}
}
//function to add the letter to the word with missing letter and print it on the lcd screen
void addletter(int questionNumber, int xval, char sprite, int missingLetters){
for (int i = 0; i < missingLetters;i++){
if (sprite == easyquestions[questionNumber].removedLetters[i]&& xval == easyquestions[questionNumber].removedIndices[i])
{
lcd.setCursor(xval,0);
lcd.print(easyquestions[questionNumber].removedLetters[i]);
easyquestions[questionNumber].removedLetters[i] = ' ';
missingLetters++;
Serial.println("Correct");
}else{
if (heartcount == 0){
lcd.clear();
lcd.setCursor(3,0);
lcd.print("Game Over");
delay(3000);
gameEnded = true;
difficultySet = false;
hearts = false;
}
}
}
}
}
```#include <LiquidCrystal.h>
#include <Wire.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
byte heart[8] = {
0b01010,
0b11111,
0b11111,
0b01110,
0b00100,
0b00000,
0b00000,
0b00000
};
int x = 0;
void setup() {
lcd.begin(16, 2);
Serial.begin(9600);
Wire.begin(4);
Wire.onReceive(receiveEvent);
lcd.createChar(0, heart);
}
void receiveEvent(int howMany)
{
while(1 < Wire.available()) // loop through all but the last
{
char c = Wire.read(); // receive byte as a character
Serial.print(c); // print the character
}
x = Wire.read(); // receive byte as an integer
Serial.println(x); // print the integer
}
int hearts = 3;
void loop(){
if (x==1){
lcd.setCursor(1,0);
lcd.write(byte(0));
lcd.write(byte(0));
lcd.write(byte(0));
}
if (x==2){
if (hearts == 0){
Wire.beginTransmission(4);
x = 5;
Wire.write(x);
Wire.endTransmission();
}else {
lcd.setCursor(hearts,0);
lcd.write(" ");
}
}
}