Issue with button presses displaying on serial monitor

Hi, I'm using an Arduino Uno and on Inventr . io's "Lesson #10: Whack an LED"

I've copy-pasted the code they provide. checked for errors. Didn't read any. sent to arduino.
...
The LEDs display as they should but the buttons I am to press corresponding to one's specific LED when lit, does not register. In the video, they show a window called "Com10". I'm using a program they had me download called "Arduino IDE". Under the coding section, if I click on "Serial Monitor", it looks like perhaps that tab that appears may be supposed to show the same thing. ...
When an LED light lights up, I'm supposed to press the corresponding button before the LED light turns off. When I do this, nothing appears in the Serial Monitor box.
...
Can anyone help me understand why this is or where the "score board" is actually being displayed, if it is, at all?

Thanks

We have no idea what that lesson is and what the code is.

So please post your code here (please do not forget to use code tags as described in How to get the best out of this forum.

Please post your sketch, using code tags when you do. This prevents parts of it being interpreted as HTML coding and makes it easier to copy for examination

In my experience the easiest way to tidy up the code and add the code tags is as follows
Start by tidying up your code by using Tools/Auto Format in the IDE to make it easier to read. Then use Edit/Copy for Forum and paste what was copied in a new reply. Code tags will have been added to the code to make it easy to read in the forum thus making it easier to provide help.

Thank you, both. I hope I did this right. In IDE, I selected the code, applied autoformatting. Then copy-pasted below, selected that and clicked the <code/> icon.

const int led_red = 2;  // Output pins for the LEDs
const int led_blue = 3;
const int led_yellow = 4;
const int led_green = 5;
const int red_button = 12;  // Input pins for the buttons
const int blue_button = 11;
const int yellow_button = 10;
const int green_button = 9;
int count = 0;      // Hit (score) counter
int playTime = 10;  // Amount of "Moles" to pop out.


/*
  functions to flash LEDs and pop up that "Mole" - (aka LED).
  */
void flash_red() {
  digitalWrite(led_red, HIGH);
  delay(1000);
  if (digitalRead(red_button) == LOW) {  // Red button
    count = count + 1;
    Serial.println(count);
  }
  digitalWrite(led_red, LOW);
}

void flash_blue() {
  digitalWrite(led_blue, HIGH);
  delay(1000);
  if (digitalRead(blue_button) == LOW) {  // Blue button
    count = count + 1;
    Serial.println(count);
  }
  digitalWrite(led_blue, LOW);
}

void flash_yellow() {
  digitalWrite(led_yellow, HIGH);
  delay(1000);
  if (digitalRead(yellow_button) == LOW) {  // Yellow button
    count = count + 1;
    Serial.println(count);
  }
  digitalWrite(led_yellow, LOW);
}

void flash_green() {
  digitalWrite(led_green, HIGH);
  delay(1000);
  if (digitalRead(green_button) == LOW) {  // Green button
    count = count + 1;
    Serial.println(count);
  }
  digitalWrite(led_green, LOW);
}

/* a function to select which mole to popup
  */
void MolePopup(long led) {
  switch (led) {
    case 0:
      flash_red();
      break;
    case 1:
      flash_green();
      break;
    case 2:
      flash_yellow();
      break;
    case 3:
      flash_blue();
      break;
  }
  delay(50);
}

// function to end the game (repeats 5 times)
void GameEnd() {
  for (int i = 0; i < 5; i++) {
    digitalWrite(led_red, HIGH);  // turn all LEDs on
    digitalWrite(led_green, HIGH);
    digitalWrite(led_yellow, HIGH);
    digitalWrite(led_blue, HIGH);
    delay(1000);
    digitalWrite(led_red, LOW);  // turn all LEDs off
    digitalWrite(led_green, LOW);
    digitalWrite(led_yellow, LOW);
    digitalWrite(led_blue, LOW);
    delay(1000);
  }
  count = 0;  // reset score
}

// function to build and play the randomized sequence
void playGame() {
  for (int i = 0; i < playTime; i++) {  // loop for length of playTime
    MolePopup(random(4));               // Have a random "mole" pop up.
  }
}

// standard sketch setup function
void setup() {
  pinMode(led_red, OUTPUT);  // configure LEDs on outputs
  pinMode(led_green, OUTPUT);
  pinMode(led_yellow, OUTPUT);
  pinMode(led_blue, OUTPUT);
  pinMode(red_button, INPUT);      // configure buttons on inputs
  digitalWrite(red_button, HIGH);  // turn on pullup resistors
  pinMode(green_button, INPUT);
  digitalWrite(green_button, HIGH);
  pinMode(yellow_button, INPUT);
  digitalWrite(yellow_button, HIGH);
  pinMode(blue_button, INPUT);
  digitalWrite(blue_button, HIGH);
  randomSeed(analogRead(5));  // random seed for sequence generation

  Serial.begin(9600);  // Where the score is displayed
}

// standard sketch loop function
void loop() {
  playGame();   // play the game
  delay(1000);  // wait a sec
  GameEnd();    // Play the game END flashing sequence.
}

You did.

I fixed a little mistake with

The < has a special meaning and as a result it looked like "" instead of "<code/>". Don't worry, just explaining in case next time you notice that something dropped.

Thanks. Any idea with the main issue I'm having?

You should have the serial monitor open and have it set to 9600 baud to match the Serial.begin(9600) in the sketch.
Each of the flash_ functions contain code like this example for red:

  if (digitalRead(red_button) == LOW) {  // Red button
    count = count + 1;
    Serial.println(count);
  }

So, assuming you have your switches wired between the input pin and ground then when pressed it should output the current value of 'count' to the serial monitor.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.