-1

Here's the code up to the error.

const int R = 12;
const int G = 10;
const int Y = 8;

const int PBR = 13;
const int PBG = 11;
const int PBY = 9;
const int pinNum = 3;
const int speaker = 2;

int LED = 0;
int gameStage = 0;

const int winNum = 2;
int gamePoint[winNum];
int rounding = 0;

unsigned long lastTime = 0;
unsigned long pause = 1000;

void ledState(int ledNum);
void clue(int rounding);
void begin_game();
void play();
void winning_sound();
void win();
void lose();
void lose_sound();
boolean inputWait(int buttonNum);


void setup() {
Serial.begin(9600);

pinMode(R, OUTPUT);
pinMode(G, OUTPUT);
pinMode(Y, OUTPUT);
pinMode(PB1, INPUT);
pinMode(PB2, INPUT);
pinMode(PB3, INPUT);
pinMode(speaker, OUTPUT);

randomSeed(analogRead(0));
}

void loop() {

if (gameStage == 0)
{
int PBvalue1 = digitalRead(PB1);
int PBvalue2 = digitalRead(PB2);
int PBvalue3 = digitalRead(PB3);
  if (PBvalue1 && PBvalue2 && PBvalue3 == 0)
  {
    begin_game();
  }
  else
  {
    Serial.println("button Pressed");
    ledState(-1);
    rounding = 0;
    delay(1500);
    gameStage = 1;
  }
}
if (gameStage == 1)
{
  **play();** Error
}

if (gameStage == 2)
{
  delay(750);
  winning_sound();
  **win();
  win();
  win();
  win();** Error
  delay(1500);
  gameStage = 0;
}

if (gameStage = 3)
{
delay(750);
lose_sound();
**lose();
lose();
lose();** Error
delay(1500);
gameStage = 0;
}

}
1
  • 1
    which variables? .... please format your code
    – jsotola
    Jan 14, 2020 at 2:51

2 Answers 2

1

Lines 5,6,7 you use PBR, PBG and PBY,

Lines 39,40 and 41 you use PB1, PB2 and PB3 Again in your void loop() you reference PB1, PB2 and PB3

0

When I tried to compile it, I got (after editing **Error**):

 In function `loop':

/sketch_jan15b.ino:55: undefined reference to `begin_game()'

/sketch_jan15b.ino:60: undefined reference to `ledState(int)'

/sketch_jan15b.ino:68: undefined reference to `play()'

/sketch_jan15b.ino:74: undefined reference to `winning_sound()'

/sketch_jan15b.ino:75: undefined reference to `win()'

/sketch_jan15b.ino:76: undefined reference to `win()'

/sketch_jan15b.ino:77: undefined reference to `win()'

These are not variables, but functions which have been declared but not defined.

Changing these:

void ledState(int ledNum);
void clue(int rounding);
void begin_game();
void play();
void winning_sound();
void win();
void lose();
void lose_sound();
boolean inputWait(int buttonNum);

to read:

void ledState(int ledNum){}
void clue(int rounding){}
void begin_game(){}
void play(){}
void winning_sound(){}
void win(){}
void lose(){}
void lose_sound(){}
boolean inputWait(int buttonNum){}

Allowed the code to compile successfully.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.