Random selections

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 6.

Moderator: Benj

Post Reply
User avatar
JLeith
Posts: 537
Joined: Wed Nov 14, 2012 7:49 pm
Location: British Columbia Canada
Has thanked: 146 times
Been thanked: 26 times
Contact:

Random selections

Post by JLeith »

Hell
I have a Halloween display of 5 ghost that activate at set intervals.

I would like to know how to Random select a ghost to activate rather then 1-2-3-4-5

I have a switch that has 5 branches going down each branch 1-2-3-4-5.

I would like a random selection
Say Ghost 1 -2-5-3-4
I would think I could run a macro Random and run a script to Select the Ghost in say Variables Ghost1, Ghost2, Ghost3, Ghost4,Ghost5

Each Ghost is activated by a relay 1-5.
I could run a branch with all 5 ghost set in 1 branch just sequence the Ghost?

Just don't know how to generate a simple 1-5 random selection

The switch is in the Relay Macro. The RA2-C0 ports


John
Attachments
Relay Driver Sept 30 2018.fcfx
(30.08 KiB) Downloaded 196 times
Ghost 1to5.png
(37.98 KiB) Downloaded 1187 times

mnf
Valued Contributor
Valued Contributor
Posts: 1188
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: Random selections

Post by mnf »

Hi John,

What a cool (or should that be ghoul?) project....

There are many ways to achieve what you want - depending on how 'random' you want the ghosts to be:
A few suggestions:

1) If the ghosts are 'started' by a sensor - then use a timer / counter and look at the value when the person trips the sensor.
2) Use an array or A LUT with a selection of 'random' sequences of ghost apparitions - then use cycle through them.
3) Use random() - and then calculate a range from the result (so ghost = random() % 5 - to give a range of 0..4) - though note that the low order bits aren't as 'random' as the higher order bits - so it might be worth a shift first. Note that this isn't truly 'random' - and you might find one ghost repeats several times (which may or may not be the effect you are after)

Once you have a 'ghost' to activate a switch statement will do the necessary...

Good luck with the project.

Martin

User avatar
JLeith
Posts: 537
Joined: Wed Nov 14, 2012 7:49 pm
Location: British Columbia Canada
Has thanked: 146 times
Been thanked: 26 times
Contact:

Re: Random selections

Post by JLeith »

Hello Martin
Thank you for the info

Yes I have a beam sensor across the sidewalk and it send a closed loop. I trigger the PIC like the button on flowcode.

I thought there might be many ways to select different orders of activation

The reason I was looking for a random selection is the average ghost routine of moving and sound takes about 40 seconds and I have 6 ghost to activate

I do this by keeping the power on the ghost and placing a insulator to one of the batteries. Then I use the N/O contacts of a relay to complete the battery connection and then the Ghost works.

Off to see what I can make happen.

John

Post Reply