Operating the Random function

Hi,

I am new to Arduino (Esplora), but I wanted to know how to to assign the number values from the random function to specific LED colors and trying to randomize the colors that appear.

I am also wondering how I can section the slider (linear potentiometer) to shortened the amount of time that the colors appear.

Any tips would be appreciated! Thanks!

I'm going off on a limb and say you are dealing with an RGB LED that has three signal pins and a ground. Is this correct?

If so, here's how you can use the random() function:

First, "set the seed" in your setup() my placing this in the setup() function:

randomSeed(analogRead(0));

Next have a variable that stores the "returned" result of the random() function by placing this in your loop():

randNumber = random(0, 2); //random number from 0 to 2 (3 values)

Next, use a Finite State Machine (FSM), which is essentially a big switch-case (just google finite state machine). The random number will determine which "state" you enter. each state will have you turn output a HIGH to a specific RGB pin on the LED and turn the others off.

That's it!

For reference:
https://www.arduino.cc/en/Reference/Random

As for the pot, just take an analog reading of it and have that reading determine the rate at which the switch-case is executed. Don't use delay(). Take a look at this first: https://www.arduino.cc/en/Tutorial/BlinkWithoutDelay

Post your code and let us know if you still have problems.

Power_Broker:
.....Next have a variable that stores the "returned" result of the random() function by placing this in your loop():

randNumber = random(0, 2); //random number from 0 to 2 (3 values)

Actually, this will produce a random number of 0 or 1. The 'max' value is exclusive, and will not be included in the returned values.
To receive a value from 0 to 2, you'd need:-

randNumber = random(0, 3); //random number from 0 to 2 (3 values)