Random Button combination

Hey guys

I am making a project for my kid's class but have no idea how to start with my code.

The purpose of the game is that you have four buttons on a bread board (in preperation fase) and a RGB led. The game need a function to randomize the combination of the 4 buttons and when its wrong the led gives a red color and when it works the led gives a green color.
But i have litterly never worked intensly with buttons and neither with randomization.

Can someone please help me with this.

Thank you. :smiley:

The game need a function to randomize the combination of the 4 buttons and when its wrong the led gives a red color and when it works the led gives a green color.

Not sure what that means. Can you describe the way the game is played in more detail?

This is the prototype but the final product will be more professional.

the intention is to randomize the four buttons every round. They get 2 oppurtuneties to guess the 2 right buttons. but the hard part is the randomizing because i dont know much about that.

I hope you got now more of an idea how the game works.

Do you have any code yet? If so post it according to the forum guidelines.

What about the random function is giving you trouble?

The random function is not that hard to understand.
If you code:

someNumber = random(5, 21);

someNumber will then get a value of 5 to 20, inclusive.

someNumber = random(16);

someNumber will be 0 to 15, inclusive.

Oh, and I would wire the buttons in a more common fashion. Wire the buttons from an input to ground and enable the internal pullup resistors. Then you do not need the external pulldown resistors. The switches will read LOW when pressed and HIGH when not pressed. An optional 0.1uF cap across the switch provides hardware debounce.

I dont really have any code yet for the buttons. I only have the code that i made for an earlier project that is a countdown timer via serial monitor.

The intention is to put it before the timer and when the right button code have been pushed the timer needs to start.

And thanks for the comments on the lay-out of the board it is indeed not the best i could do

int groenepin = 0;
int rodepin = 1;
int button0 = 2;
int button1 = 3;
int button2 = 4;
int button3 = 5; 

int min = 0;
int sec = 10;
unsigned long oneSecond = 1000UL;
unsigned long startTime;

void setup(){ 
  Serial.begin(9600);
  sec = sec + 60 * min;

  pinMode(groenepin, OUTPUT);  
  pinMode(rodepin, OUTPUT); 
  pinMode(button0, INPUT); 
  pinMode(button1, INPUT); 
  pinMode(button2, INPUT); 
  pinMode(button3, INPUT); 
   
}

void loop()
{
  if (millis() - startTime >= oneSecond)
  {    
    sec--;
    startTime += oneSecond;
    if (sec < 0) Einde();
    int displayMin = sec/60;
    if (displayMin < 10) Serial.print("0");
    Serial.print(displayMin);
    Serial.print(":");
    int displaySec = sec % 60;
    if (displaySec < 10) Serial.print("0");
    Serial.println(sec % 60);         
  }
  digitalWrite(groenepin,HIGH);
  digitalWrite(rodepin,LOW); 
  }
void Einde()
{
  
  Serial.println("Je tijd is om, begin opnieuw");
  while(1)
  digitalWrite(rodepin,HIGH); 
  digitalWrite(groenepin,LOW);   
  }

The senteces are writed in dutch. And maybe some things i could write better because i am learning most likely from internet and i begon not so long ago.

That looks like an Arduino UNO clone. When you use "Serial.begin()" in setup() you can't use Pin 0 and Pin 1 for digital I/O. Those are the serial RX and TX pins. Pick other pins.