May 20, 2024, 09:59:40 AM

News:

You can now use Vixen to program your Prop-1 and Prop-2 controllers!  Get started quickly and easily, without having to learn PBASIC.  Details in the Library forum.


2008 Project - Haunted Mine Shaft Elevator

Started by bpenman, July 27, 2008, 07:31:32 PM

Previous topic - Next topic

bpenman

I won't waste too much time with blabber, but for this Halloween, I am trying to build a simplified version of a Hellevator.

I have a prop-1 connected to a VMusic2, but also need to connect two solenoids. One to let air into the cylinders and one to let air out. I realize its probably simple, but I am no programmer and the language of Basic is still foreign to me.

Button Trigger Starts Event
Play audio track "elevator"
At X time, have the solenoid#1 fill the air for X time
At X time, have the solenoid#2 empty the air for X time
At X time, have the solenoid#1 fill the air for X time
At X time, have the solenoid#2 empty the air for X time

Second Button Trigger = Emergency Stop/Reset
Stop All Audio
Solenoid#2 Empties Air

Anybody is welcome to help me out.

Thank you, In advance!

JonnyMac

Can you give better definitions for "At time X"?  I have a program fleshed out, but would like to put the timing in for you.

And have to connected and used the VMUSIC player?
Jon McPhalen
EFX-TEK Hollywood Office

bpenman

Time X is yet to be determined. I will have to fill out that information through trial and error with the audio track. I have connected and tested the VMusic, the only problem I am having is that it sounds like it is stuttering or skipping, and I am not exactly certain why...

bpenman


JonnyMac

Okay, then, can you just make a wild guess.  The problem for me is that you only use "X" which I read as everything happening at the same time, even though you have four things listed.  Just do your best guessing about timing so I can put something into the code; you can fine tune it with the audio track later.

Thanks for the belated b-day wishes.
Jon McPhalen
EFX-TEK Hollywood Office

bpenman

Button Trigger Starts Event
Play audio track "elevator"
At 15000 time, have the solenoid#1 fill the air for 1000 time
Wait 3500
Solenoid#2 empty the air for 3000 time
Wait 5000
Solenoid#1 fill the air for 700 time
Wait 100
Solenoid#2 empty the air for 10000 time

Second Button Trigger = Emergency Stop/Reset
Stop All Audio AND
Solenoid#2 Empties Air 10000

END

bpenman

Very Rough, but at least it give us both a starting point.

JonnyMac

Here you go.  This is the easiest way to implement your program, but not the most efficient -- and if you extend it to far you will 1) run out of memory or, 2) run out of GOSUBs (you can only have 16).  I think I would opt for a table-driven approach to the valve control section; it will use less memory and eliminate the possible limits with GOSUB vis-a-vis the BASIC Stamp 1.

' =========================================================================
'
'   File...... Mine_Shaft.BS1
'   Purpose...
'   Author.... Jon Williams, EFX-TEK
'              Copyright (c) 2008 EFX-TEK
'              Some Rights Reserved
'              -- see http://creativecommons.org/licenses/by/3.0/
'   E-mail.... jwilliams@efx-tek.com
'   Started...
'   Updated... 27 JUL 2008
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------


' -----[ Revision History ]------------------------------------------------


' -----[ I/O Definitions ]-------------------------------------------------

SYMBOL  RX              = 7                     ' SETUP = UP, no ULN
SYMBOL  TX              = 6                     ' SETUP = UP, no ULN
SYMBOL  Trigger         = PIN5                  ' active-high input
SYMBOL  EStop           = PIN4                  ' active-high input

SYMBOL  DumpValve       = PIN1
SYMBOL  FillValve       = PIN0


' -----[ Constants ]-------------------------------------------------------

SYMBOL  IsOn            = 1                     ' for active-high in/out
SYMBOL  IsOff           = 0

SYMBOL  Pressed         = 1
SYMBOL  NotPressed      = 0

SYMBOL  Baud            = OT2400


' -----[ Variables ]-------------------------------------------------------

SYMBOL  tix             = B2
SYMBOL  volume          = B3


' -----[ Initialization ]--------------------------------------------------

Reset:
  PINS = %00000000                              ' clear all outputs
  DIRS = %00000011                              ' make P0-P1 outputs

  PAUSE 2250                                    ' let VMUSIC power up
  GOSUB VM_Stop                                 ' stop if playing
  GOSUB VM_Wait_Prompt


' -----[ Program Code ]----------------------------------------------------

Main:
  tix = 0                                       ' reset timer

Check_Trigger:
  PAUSE 5                                       ' loop pad
  tix = tix + 5 * Trigger                       ' update timer
  IF tix < 100 THEN Check_Trigger               ' wait for 0.1 sec input

Start_Audio:
  SEROUT TX, Baud, ("VPF elevator.mp3", 13)
  GOSUB VM_Wait_Start

  tix = 150
  GOSUB Pause_Tix                               ' delay 15000

  FillValve = IsOn
  tix = 10
  GOSUB Pause_Tix                               ' delay 1000

  FillValve = IsOff
  tix = 35
  GOSUB Pause_Tix                               ' delay 3500

  DumpValve = IsOn
  tix = 30
  GOSUB Pause_Tix                               ' delay 3000

  DumpValve = IsOff
  tix = 50
  GOSUB Pause_Tix                               ' delay 5000

  FillValve = IsOn
  tix = 7
  GOSUB Pause_Tix                               ' delay 700

  FillValve = IsOff
  tix = 1
  GOSUB Pause_Tix                               ' delay 100

  DumpValve = IsOn
  tix = 100
  GOSUB Pause_Tix                               ' delay 10000

  GOTO Reset                                    ' both valves off


' -----[ Subroutines ]-----------------------------------------------------

' Delay in 0.1 second units
' -- scans e-stop button for press

Pause_Tix:
  IF tix = 0 THEN Pause_Tix_Exit
    IF EStop = Pressed THEN Emergency_Stop
      PAUSE 100
      tix = tix - 1
      GOTO Pause_Tix

Pause_Tix_Exit:
  RETURN

' -------------------------------------------------------------------------

Emergency_Stop:
  GOSUB VM_Stop
  DumpValve = IsOn
  PAUSE 10000
  GOTO Reset                                    ' both valves off

' -------------------------------------------------------------------------

VM_Wait_Start :
  SERIN RX, Baud, ("T $0")
  RETURN

' -------------------------------------------------------------------------

VM_Stop:
  SEROUT TX, Baud, ("VST", 13)
  RETURN

' -------------------------------------------------------------------------

' Pass volume (0 = loudest, 254 = muted) in "volume"

VM_Volume:
  volume = volume MAX $FE                       ' limit per spec
  SEROUT TX, Baud, ("VSV ", #volume, 13)
  RETURN

' -------------------------------------------------------------------------

VM_Wait_Prompt:
  SERIN RX, Baud, (">")
  RETURN

' -------------------------------------------------------------------------


' -------------------------------------------------------------------------


' -----[ User Data ]-------------------------------------------------------
Jon McPhalen
EFX-TEK Hollywood Office

bpenman

BOY! Thanks! I would have never been able to do that by myself.

Caretaker.CCI

The amazing thing is that you can (or will be able to) do it yourself.

Take what Jon has created here and study every detail in the code. It will make more sense because the program is making your effect do what you want it to. If you don't understand what a particular line in the code is doing, look it up using the help menu in PBASIC or use one of the many (often free) books available to you. Jon's book "Stamp Works" is a good resource. Here's the link:

http://www.parallax.com/Portals/0/Downloads/docs/books/sw/Web-SW-v2.1.pdf

Come back to this forum often and read what others are trying to do. Try to follow the code for anything that looks interesting (or just at your level of understanding). Soon you will be able to create your own programs!

Greg