for loop - How do I establish multiple random numbers in a single Arduino sketch? -
i have arduino sketch i'm planning control 8 leds blink or fade @ different rates. want set random number 1-8random output pin, random number 30-300 delay()
value within loop, , third random number +=x
controlling velocity of fade in or out. i'd establish random number dictates whether light blinks or fades (a boolean random work here...).
here's i'm fuzzy. documentation, gleaned randomseed()
function drive random(x,y)
, seems infer random(x,y)
values define use same seed within same sketch.
there did not seem way define seed drive random , seed b drive random b. reading right? unable find samples want do.
pseudocode below:
void setup() { pinmode(12, output); pinmode(11, output); pinmode(10, output); pinmode(9, output); pinmode(8, output); pinmode(7, output); pinmode(6, output); pinmode(5, output); pinmode(4, output); } void loop() { # # how can assocaiate pinseed pin, delayseed delay , velseed velocity? # int pinseed = randomseed(analogread(0)); int pin = random1(4,13); int delayseed = randomseed(analogread(0)); int delay = random(30,200); int velseed = randomseed(analogread(0); int velocity = random(1,21); (i=0;i=255;+=velocity) { analogwrite(pin,i); delay(velocity); } }
a seed value sets starting point sequence of random (psuedo-random actually) numbers. after seed set can draw random numbers, not reset or redefine seed second random number. seed required generated once in program.
being able set seed allows re-create sequence of random numbers on second, third, etc. execution of code. helps debugging!
also, each random number returned can normalized different range of values, in 1-8 or 30-300, , boolean can defined < 5 (false) or >= 5 (true) when random number normalized 1 thru 10 (for example).
hope helps.
Comments
Post a Comment