question using Random with a code

69-cat

Member
I am currently working on swapping over all of my Halloween props from PLC to PICAXE controlled. I have received some help from fellow Haunters on basic setting up and modify as needed but came across my Electric Chair prop and ran into a small problem. During the triggering of the code, I have a section that controls a solenoid valve which moves the prop back and forth in the chair. So my question is, can a "random" command be used to control the output while the "shake" output is HIGH. What I am looking for is a very rapid/violent (on/off) simulation during the shocking stage of the run.
Dave

Code:
#Picaxe 14M2

'b.0 = strobes

'b.1 = screams

'b.2 = shake

'b.3 = smoke

'b.4 = shock

'c.3 = PIR


symbol strobes = b.0

symbol screams = b.1

symbol shake = b.2

symbol smoke = b.3

symbol shock = b.4

symbol PIR_IN = pinC.3

symbol PIR_COUNT=b5




 

 

start:

wait 20                                       'delay to allow PIR to settle


 

 

standby: 

                

                 Do : Loop Until PIR_IN=1                            

                

                Do

                PIR_COUNT = PIR_COUNT + 1 * PIR_IN

                Loop Until PIR_COUNT = 2

                PIR_COUNT = 0                 

                goto activate 



activate:  

high strobes

wait 2

high screams

wait 2

high shake

wait 5

high smoke

wait 1

high shock

wait 6

low screams

low shake

wait 3

low smoke

low shock

wait 2

low strobes

wait 10

goto standby
 

westaust55

Moderator
I am not sure that I understand exactly how you want to use RANDOM.
Certainly it can be used to control an output.
You do not indicate which output pin you wish to control when the output Shake (B.2) is high so you need to change Your_Output_pin to suit your pin allocation.

Try this structure (untested):
Code:
let w1 = timer ; seed w1 with timer value
;
;
;
DO WHILE OutpinB.2 = 1 ; while Shake = 1/high
   RANDOM w1 ; put random value into w1
   Your_Output_pin = w0 AND 1 ;  your output pin is then 0 or 1 as determined by random
LOOP
A more uniform on off for the output you wish to control but potentially faster would be

Code:
DO WHILE OutpinB.2 = 1 ; while Shake = 1/high
   TOGGLE your_output_pin
LOOP
LOW your_output_pin ; make sure off at the end of sequence
 

Buzby

Senior Member
Hi Westie,

That code will shake the chair *very* fast.

I think he'll need a little PAUSE somewhere.

Cheers,

Buzby
 

westaust55

Moderator
What was asked for is:
What I am looking for is a very rapid/violent (on/off)
but yes, if too fast then introduce a PAUSE.
Since the posted code includes WAIT commands suggest the OP knows about this delay methodology.
 
Top