' ========================================================================= ' ' File...... Scare_crow_test.SXB ' Purpose... Run arms of an animatronic scarecrow ' Author.... Wesley Bourn ' E-mail.... ' Started... May 21, 2006 ' Updated... May 27, 2006 ' ' ========================================================================= ' ------------------------------------------------------------------------- ' Program Description ' ------------------------------------------------------------------------- ' ' Simple LED blinker using HIGH and LOW. ' ------------------------------------------------------------------------- ' Device Settings ' ------------------------------------------------------------------------- DEVICE SX48, OSC1MHZ, TURBO, STACKX, OPTIONX FREQ 1_000_000 ' ------------------------------------------------------------------------- ' IO Pins ' ------------------------------------------------------------------------- motion VAR RE.7 ' motion detect left_arm VAR RE.3 ' Left forearm left_sh VAR RE.2 ' Left shoulder rt_arm VAR RE.1 ' Right arm rt_sh VAR RE.0 ' Right shoulder blink VAR RE.6 ' indicate which program is gonna run ' ------------------------------------------------------------------------- ' Constants ' ------------------------------------------------------------------------- timer VAR byte choice VAR byte idx VAR byte ' ========================================================================= PROGRAM Start ' ========================================================================= ' ------------------------------------------------------------------------- ' Program Code ' ------------------------------------------------------------------------- Start: TRIS_E=$80 ' one input, rest outputs timer = 123 DO ' wait for motion detect and generate random # RANDOM timer LOOP UNTIL motion = 0 choice = timer // 10 ' make the random be a 1 - 10 choice = choice + 1 if choice <= 6 then ' GET ROUTINE # 1 HOPEFULLY 60% of time high blink pause 250 low blink pause 250 HIGH left_sh ' start left arm in PAUSE 750 HIGH left_arm ' start left forearm in PAUSE 4000 LOW left_arm ' release left forearm momentarily PAUSE 1000 HIGH left_arm ' move left forearm back in HIGH rt_sh ' rotate right shoulder PAUSE 2500 HIGH rt_arm ' start to raise arm PAUSE 2300 LOW rt_sh ' swing right arm down PAUSE 2000 LOW left_arm ' start to reset the arms LOW left_sh PAUSE 1000 LOW rt_arm GOTO nearend endif if choice <= 8 then ' GET ROUTINE # 2 HOPEFULLY 20% OF TIME for idx = 0 to 1 high blink pause 250 low blink pause 250 next HIGH left_sh ' Just do a arms in, grab type motion HIGH rt_arm PAUSE 3500 LOW left_sh LOW rt_arm GOTO nearend endif for idx = 0 to 2 high blink pause 250 low blink pause 250 next HIGH rt_sh ' WELL, IF NOT OTHER 2 CHOICES, SHOULD BE THIS ONE THEN 20% PAUSE 2500 ' act like a swing left arm motion, but don't HIGH rt_arm PAUSE 2800 LOW rt_arm PAUSE 3000 LOW rt_sh nearend: ' pause then go back to beginning PAUSE 10000 ' wait 10 seconds to slow activation down GOTO Start ' back to beginning for motion detect