small RGB LED slotmachine. Help needed.

Hi,

I’m working on a small arduino project and i’m stuck. Hope u guys can help. A dangershield is on the arduino.

What it needs to do is:
put a random color on the RGB LED every time a button is pressed. The first 5 seconds it just shows some random colors like the spinning effect on a real slotmachines. If you have 3 the same color you should hear a sound(blink the LEDs few time also good) if not 3 the same color u lose. You have 5 coins/lives and if you lose -1 if you win +2. You can see you lives on the dangershields number display.

Where i’m stuck:
He now only does the random thing ones and it stops. What it should do is do the same thing every time I press the button.
and how do i make it so you hear a sound if you have 3 the same color(pref this but blinking the leds few time also good)?

long randNumber1;
long randNumber2;
long randNumber3;

int buttonPin = 11;
int buttonState = 0;
unsigned long startTime = millis();
unsigned long interval = 5000UL; // 5 seconds

int redPin1 = 13;    // Red LED
int grnPin1 = 12;    // Green LED
int bluPin1 = 11;    // Blue LED

int redPin2 = 10;    // Red LED
int grnPin2 = 9;     // Green LED
int bluPin2 = 8;     // Blue LED

int redPin3 = 7;    //Red LED
int grnPin3 = 6;    // Green LED
int bluPin3 = 5;    // Blue LE


void setup(){

  Serial.begin(9600);

  pinMode(redPin1, OUTPUT);
  pinMode(grnPin1, OUTPUT);
  pinMode(bluPin1, OUTPUT);

  pinMode(redPin2, OUTPUT);
  pinMode(grnPin2, OUTPUT);
  pinMode(bluPin2, OUTPUT);

  pinMode(redPin3, OUTPUT);
  pinMode(grnPin3, OUTPUT);
  pinMode(bluPin3, OUTPUT);

  pinMode(buttonPin, INPUT);
}

void loop() {

  buttonState = digitalRead(buttonPin);
  if (buttonState == LOW){
    while(millis() - startTime < interval){    

      //LED_Lamp_1
      randNumber1 = random(1, 4);
      if (randNumber1 == 1){

        digitalWrite(redPin1, HIGH); // red
        digitalWrite(grnPin1, LOW); //green
        digitalWrite(bluPin1, LOW); //blue
      }
      else if (randNumber1 == 2){

        digitalWrite(redPin1, LOW); // red
        digitalWrite(grnPin1, HIGH); //green
        digitalWrite(bluPin1, LOW); //blue

      }
      else if (randNumber1 == 3){

        digitalWrite(redPin1, LOW); // red
        digitalWrite(grnPin1, LOW); //green
        digitalWrite(bluPin1, HIGH); //blue

      }
      //LED_Lamp_2
      randNumber2 = random(4, 7);
      if (randNumber2 == 4){

        digitalWrite(redPin2, HIGH); // red
        digitalWrite(grnPin2, LOW); //green
        digitalWrite(bluPin2, LOW); //blue
      }
      else if (randNumber2 == 5){

        digitalWrite(redPin2, LOW); // red
        digitalWrite(grnPin2, HIGH); //green
        digitalWrite(bluPin2, LOW); //blue

      }
      else if (randNumber2 == 6){

        digitalWrite(redPin2, LOW); // red
        digitalWrite(grnPin2, LOW); //green
        digitalWrite(bluPin2, HIGH); //blue

      }

      //LED_Lamp_3
      randNumber3 = random(7, 10);
      if (randNumber3 == 7){

        digitalWrite(redPin3, HIGH); // red
        digitalWrite(grnPin3, LOW); //green
        digitalWrite(bluPin3, LOW); //blue
      }
      else if (randNumber3 == 8){

        digitalWrite(redPin3, LOW); // red
        digitalWrite(grnPin3, HIGH); //green
        digitalWrite(bluPin3, LOW); //blue

      }
      else if (randNumber3 == 9){

        digitalWrite(redPin3, LOW); // red
        digitalWrite(grnPin3, LOW); //green
        digitalWrite(bluPin3, HIGH); //blue

      }
      delay(500);
    }

  }
}

He now only does the random thing ones and it stops. What it should do is do the same thing every time I press the button.

That is because you never refresh the value in startTime. If you reset this to the value in millis() once you have done your sequence it will repeat.

how do i make it so you hear a sound if you have 3 the same color

use an if statement to see if all three of your random numbers are the same.

Grumpy_Mike:

He now only does the random thing ones and it stops. What it should do is do the same thing every time I press the button.

That is because you never refresh the value in startTime. If you reset this to the value in millis() once you have done your sequence it will repeat.

how do i make it so you hear a sound if you have 3 the same color

use an if statement to see if all three of your random numbers are the same.

How can i refresh the value and where do i need to place it so it will work?

I got a working code for the same color.

How can i refresh the value and where do i need to place it so it will work?

You refreshe it by setting start time equal to the current milis time.
You place it at then end of the section of code that you do when millis-start time is less than the interval.

Did. You write that code?

Thx, I got a working code now, and yes i wrote the code.

Teted:
yes i wrote the code.

Well done.

You can shorten it substantially by using arrays you know:-
http://www.thebox.myzen.co.uk/Tutorial/Arrays.html