' ========================================================================= ' ' File....... Sequencer.BS1 ' Purpose.... Sequencer Engine for Props ' Author..... Jon Williams -- Parallax, Inc. ' Adaptation. Vern Graner ' Started.... 07 JUN 2005 ' Updated.... 21 SEP 2005 ' ' {$STAMP BS1} ' {$PBASIC 1.0} ' ' ========================================================================= ' -----[ Program Description ]--------------------------------------------- ' Adapted Jon Williams "drum sequencer" style program to control a ' solenoid valve and a sond module when triggered by a PING sonar module ' -----[ Revision History ]------------------------------------------------ ' -----[ I/O Definitions ]------------------------------------------------- SYMBOL Solenoid = PIN0 ' Solenoid connected to PIN 0 SYMBOL SoundModule = PIN1 ' SoundModule connected to PIN 0 SYMBOL PINGSonar = PIN7 ' Parallax PING)) sensor on PIN 7 ' -----[ Constants ]------------------------------------------------------- SYMBOL Yes = 1 ' for active-high input SYMBOL No = 0 SYMBOL DelayRes = 100 ' 100 ms delay resolution SYMBOL Threshold = 1000 ' Value represents approx 7ft from ping sensor ' -----[ Variables ]------------------------------------------------------- SYMBOL Pntr = B0 ' record pointer SYMBOL CTRL = B1 ' control outputs SYMBOL Timer = B2 ' step timer ( x DelayRes ) SYMBOL Distance = W5 ' holds the PINGSonar result ' -----[ EEPROM Data ]----------------------------------------------------- ' Sequence Database ' -- each entry has two bytes: outputs, timing (1 - 255 units x DelayRes) Main: ' |-PIN0 (Solenoid) ' ||-PIN1 (Sound Module) ' |||-PIN2 ' ||||-PIN3 ' |||||-PIN4 ' ||||||-PIN5 ' |||||||-PIN6 ' ||||||||-PIN7 ' |||||||| |-Timing byte value ' |||||||| | EEPROM (%11000000, 2) EEPROM (%01000000, 2) EEPROM (%11000000, 4) EEPROM (%01000000, 2) EEPROM (%11000000, 2) EEPROM (%01000000, 7) EEPROM (%11000000, 3) EEPROM (%01000000, 10) EEPROM (%11000000, 3) EEPROM (%01000000, 3) EEPROM (%11000000, 3) EEPROM (%00000000, 0) '<-- By making Timing byte=0 we signify END of sequence ' -----[ Initialization ]-------------------------------------------------- Reset: DIRS = %01111111 ' P0 - P6 are outputs ' -----[ Program Code ]---------------------------------------------------- WaitForTrigger: PULSOUT PINGSonar, 5 ' Send a Sonar pulse via the PING)) module PULSIN PINGSonar, 1, DISTANCE ' Listen for the reflection PAUSE 30 ' Let echos fade to avoid false triggering DEBUG CLS, "Distance=", DISTANCE, CR ' Echo the distance to the debug screen (comment out for live code) IF DISTANCE < THRESHOLD THEN WaitForTrigger ' If nothing is in range, ping again Sequencer: pntr = 0 ' reset record pointer Get_Record: READ pntr, ctrl ' read outputs pntr = pntr + 1 ' point to timing byte READ pntr, timer ' read timing byte pntr = pntr + 1 ' point to next record IF timer = 0 THEN Main ' test for end Update_Outputs: PINS = ctrl ' refresh output pins Delay: PAUSE DelayRes ' wait timer = timer - 1 ' update timer IF timer = 0 THEN Get_Record ' expired? GOTO Delay ' -- no, keep timing END