' © Wolfstone, 2005 ' ========================================================================= ' ' File....... BeastTest ' Purpose.... Test the Crate Beast ' Author..... Dennis Griesser ' E-mail..... wolfstone@pobox.com ' ' {$STAMP BS1} ' {$PBASIC 1.0} ' ' ========================================================================= ' -----[ Program Description ]--------------------------------------------- ' ' Test program for the Crate Beast Halloween prop - test inputs, try outputs. ' ' For information about the I/O, peripheral boards, etc, please see ' BeastControllerSetup.txt ' -----[ Revision History ]------------------------------------------------ ' BeastTest_01.bs1 - 14 October 2007 ' -----[ I/O Definitions ]------------------------------------------------- SYMBOL TrigBeast = PIN7 ' input trigger on P7 - jumpered for pull-down SYMBOL TrigLid = PIN6 ' input trigger on P6 - jumpered for pull-down SYMBOL RedLED = PIN5 ' output debug feedback on P5 - bare LED SYMBOL GreenLED = PIN4 ' output debug feedback on P4 - bare LED SYMBOL Sio = 0 ' serial I/O on P0 ' -----[ Constants ]------------------------------------------------------- ' Communication with DC-16 Digital Control Board: SYMBOL Baud = OT2400 ' serial rate to talk to DC-16 SYMBOL Addr = %00 ' address of DC-16 board (%00 - %11) ' Solenoids: SYMBOL DoorOpen = 1 ' Open Door SYMBOL DoorClose = 2 ' Close Door SYMBOL ArmOpen = 3 ' Open Arm SYMBOL ArmClose = 4 ' Close Arm SYMBOL BeastOpen = 13 ' Open Beast SYMBOL BeastClose = 14 ' Close Beast SYMBOL LidOpen = 15 ' Open Lid SYMBOL LidClose = 16 ' Close Lid SYMBOL IsOff = 0 SYMBOL IsOn = 1 ' -----[ Variables ]------------------------------------------------------- SYMBOL RndNum = W0 ' 16-bit random number (and seed for next one) SYMBOL Solenoid = W1 SYMBOL Delay = W2 SYMBOL Cycles = B6 ' Using GOSUB on the BS1 requires variables B12 and B13 (W6) ' -----[ EEPROM Data ]----------------------------------------------------- ' -----[ Initialization ]-------------------------------------------------- Reset: ' 76543210 ' bit positions DIRS = %00111111 ' make P7-P6 inputs, P5-P0 outputs PINS = %00000000 ' all outputs off RedLED = IsOn ' turn on red LED to show LED works GreenLED = IsOn ' turn on green LED to show LED works SEROUT Sio, Baud, ("!DC16", Addr, "X") ' turn off all solenoids PAUSE 1000 ' wait 1.0 second GOSUB Clear ' Reset all solenoids to Normally Closed ' -----[ Program Code ]---------------------------------------------------- ' The main loop just sits and spins until it sees an incoming command. Main: ' IF TrigBeast = IsOn THEN DoBeast ' wait until trigger is activated ' IF TrigLid = IsOn THEN DoLid ' wait until trigger is activated IF TrigBeast = IsOn OR TrigLid = IsOn THEN TestOutputs ' run big test cycle GOTO Main ' This routine controls the whole "Show The Beast" function. ' After a nice Beast session, we return to the main loop. DoBeast: FOR Cycles = 0 TO 5 RedLED = IsOn ' flash red LED to show switch works PAUSE 500 ' wait .5 second RedLED = IsOff PAUSE 500 ' wait .5 second NEXT GOTO Main ' return to the main loop to await new command ' This routine controls the whole "Bang The Lid" function. ' After a good solid bang session, we return to the main loop. DoLid: FOR Cycles = 0 TO 5 GreenLED = IsOn ' flash green LED to show switch works PAUSE 500 ' wait .5 second GreenLED = IsOff PAUSE 500 ' wait .5 second NEXT GOTO Main ' return to the main loop to await new command ' Test everything, in sequence! TestOutputs: ' Open lid Solenoid = LidOpen GOSUB Ping ' Leave open for small time PAUSE 500 ' wait .5 second ' Close lid Solenoid = LidClose GOSUB Ping ' Open doors Solenoid = DoorOpen GOSUB Ping PAUSE 2000 ' wait 2.0 second for doors to open ' Show Beast Solenoid = BeastOpen GOSUB Ping PAUSE 5000 ' wait 5.0 second for Beast to deploy and scare! ' Hide Beast Solenoid = BeastClose GOSUB Ping PAUSE 2000 ' wait 2.0 second for Beast to withdraw ' Close doors Solenoid = DoorClose GOSUB Ping GOTO Main ' return to the main loop to await new command END ' -----[ Subroutines ]----------------------------------------------------- ' Using GOSUB on the BS1 requires variables B12 and B13 (W6), making those ' variables unavailable for general program use. ' Reset all solenoids to Normally Closed position. ' We have to do this because the solenoids are bistable. Clear: Solenoid = BeastClose ' close Beast GOSUB Ping Solenoid = LidClose ' close Lid GOSUB Ping Solenoid = ArmClose ' close Arm GOSUB Ping Solenoid = DoorClose ' close Door GOSUB Ping RETURN ' Fire one solenoid _coil_ and return it to rest state. ' Since the valves are bistable, it is a good idea to remove ' power after every operation is complete. Removing power does not ' change the position of the pneumatic valve! Ping: ' Fire the solenoid that we want, and wait for it to happen. ' According to our experiments (backed by the LTV data sheet), ' it takes up to 30 mSec for the valve to switch. SEROUT Sio, Baud, ("!DC16", Addr, "P", Solenoid, IsOn) ' turn on PAUSE 100 ' wait .03 second for valve to respond ' The valve has switched. Remove the solenoid power. After sending ' this command, we must wait a little while for the parallel board ' to finish executing before we send another command. SEROUT Sio, Baud, ("!DC16", Addr, "P", Solenoid, IsOff) ' turn off PAUSE 5 ' wait .005 second for parallel board RETURN