System with two buttons

How to design system with two buttons Arduino send two message randomly , "hit b1" or "hit b2", if the user makes the correct move increment the score once

When is the assignment due?

2 Likes

What is Your background and Your knowledge and for what Arduino?

You could also break it down thus - are you having problems with

  1. Designing two buttons
  2. Sending messages
  3. Incrementing a score

???

I beginner with Arduino still not good and using uno

Sending messages

Look at the serial examples that ship with the IDE. They thought of that. :slight_smile:

1 Like

One challenge you’ll hit soon…
How does the Arduino know if it’s a correct score.

It’s fine having two buttons and messages, but why is one correct, and the other not ?

Actually, with no time limit, it's easy to get a 100% score. :slight_smile: It says, "hit 1", I sit there and peer intensely at the buttons, find the right one, double check, triple check and then press it. Profit!

Also there is no penalty for mistakes. :slight_smile:

Alright now i have Inquiry when i push the button it give me low not high and when i did not push it always high

Is that a problem? Just test for a LOW. If you have actual code, please post it here in code tags please.

It is not a real problem but i want to know why
Here is the code

long randNumber;
bool button_state1,button_state2;
int button_pin1=2;
int button_pin2=3;
int score=0;
 void setup() {
  Serial.begin(9600);
  pinMode(button_pin1, INPUT_PULLUP);
  pinMode(button_pin2, INPUT_PULLUP);
  randomSeed(analogRead(0));
}

void loop() {

  randNumber = random(1,3);
  button_state1 = digitalRead(button_pin1);
  button_state2 = digitalRead(button_pin2);
  Serial.println(randNumber);
  Serial.print("button state 1 = ");
  Serial.println(button_state1);
  Serial.print("button state 2 = ");
  Serial.println(button_state2);


  if(randNumber==1 && button_state1==0 || randNumber==2 && button_state2==0)
  {
    score++;
    Serial.println("You did the correct move");
    Serial.print("score= ");
    Serial.println(score);

  }
  else
  {
    Serial.println("You did not make the correct move");
    Serial.print("score= ");
    Serial.println(score);
  }

  delay(10000);
}

It's hardware. Post a wiring diagram.

Yeah, not a diagram, but okay. How did you know to connect it that way?

based on this

Thought experiment for you... if you could assign "ground" a state, would it be HIGH or LOW? In other words, is ground effectively HIGH or LOW? What does the switch connect the GPIO to when it is pressed?

Your post was MOVED to its current location as it is more suitable.

Could you also take a few moments to Learn How To Use The Forum.

Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.

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