Random LED's

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
alek0161
Posts: 1
Joined: Sat Apr 13, 2013 7:58 am

Random LED's

Post by alek0161 »

Dear fellow Flowcode users

My wish is to create a small program which can generate a random variable and then make a random led turn on.
So far I have two LEDarrays with 3 leds in each and I want one LED to be turned on in each LEDarray, the LED should be selected by the random variable. As I do not want the same LED in each LEDarray to turn on, I have made two different random variables. BUT the two random variables generate the same random value each time.
My quenstion is: How can I make different variables generate different values in the same program?

I really hope anybody is able to help. If there is any quenstions please ask me.

Best regards
Aleksander Rosenkilde Kristiansen

P.S. I have attached my program.
Attachments
random_led_rigtig.fcf_avr
(11.5 KiB) Downloaded 286 times

User avatar
JonnyW
Posts: 1230
Joined: Fri Oct 29, 2010 9:13 am
Location: Matrix Multimedia Ltd
Has thanked: 63 times
Been thanked: 290 times
Contact:

Re: Random LED's

Post by JonnyW »

Hello Aleksander.

Flowcode has a random number function, random(), built in. This should return a different value each time you call it.

If this is not what you are after or are using (sorry - I have Linux at home so can not see your program) Here is some pseudo-code for a simple random 16-bit number. Note the 'randval' global variable is not initialised at the start. This helps with a different random number each time.

Code: Select all

randval = randval + 0xCA56
randval = (randval >> 3) + (randval << 13)
.Return = randval
You can call this constantly in a timer interrupt if you want, or each time you need it. Then, if you want a value between 0 and N do:

Code: Select all

value = GetRandom()
value = value MOD N
It may also help to look at Martins lottery generator, here:
http://www.matrixmultimedia.com/mmforum ... 885#p22091

Good luck,

Jonny

Post Reply