November 23, 2024, 09:43:10 AM

News:

Be sure to checkout our Vixen interfaces in the Library forum -- if you want PC automation at near zero cost, EFX-TEK and Vixen is a great combination of tools.


Prop-1 Program to control pirate cannon

Started by JezzieRose, September 18, 2010, 12:19:09 PM

Previous topic - Next topic

JezzieRose

We have all the parts hooked-up and by modifying your MIB.bs1 program we are able to test each component and they all work.

Now we need help with the program to get the timing and the reset to work properly.

' -----[ Program Description ]---------------------------------------------
'
' Connections on Prop-1 with ULN2003 chip
'
' P7 -   Serial connection to RC4 (with its own power) relay K4 that controls fogger remote
'
' P5 -   Active-high trigger input
'        * Push button
'        * N.O. button/switch between P5.W and P5.R
'
' OUT4 - Pulse out to audio player (Explosion)
'        * use V+/OUT4 to send 12v pulse to Cowlacious CAR/P 325
'
' OUT3 - Control to 12v light (Blast)
'        * use V+/OUT3 to 12v LED automotive brake light/turn light
'
' OUT2 - Control to red LED light (Fuse)
'        * use V+/OUT2 to 5mm LED with 470 ohm resistor
'
' OUT1 - To solenoid on air tank that controls blast of air out of cannon
'
 
The goal is to push the Trigger button -
Start Fooger and Fuse light
  - have the Fuse light flicker fast on and off
  - run for 3sec then off
Start Audio, Blast light and Air Blast
- Air Blast runs for 1sec
- Blast light is on for 3sec
- Audio runs for approx 3 sec
Reset and wait for Trigger to be pushed

Please let me know if you need any more information.

Thank you very much for any help you can give us.


JonnyMac

September 18, 2010, 12:53:07 PM #1 Last Edit: September 18, 2010, 02:34:00 PM by JonnyMac
Give this a whirl.

Updated!

' =========================================================================
'
'   File......
'   Purpose...
'   Author....
'   E-mail....
'   Started...
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  Sio             = 7                     ' SETUP = UP; no ULN

SYMBOL  Trigger         = PIN6                  ' SETUP = DN

SYMBOL  Audio           = PIN4
SYMBOL  Flash           = PIN3
SYMBOL  Fuse            = PIN2
SYMBOL  AirBlast        = PIN1


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

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

SYMBOL  Baud            = OT2400


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

SYMBOL  relays          = B0
SYMBOL   Fogger         =  BIT0
SYMBOL   K2             =  BIT1
SYMBOL   K3             =  BIT2
SYMBOL   K4             =  BIT3

SYMBOL  delay           = B2

SYMBOL  timer           = W4
SYMBOL  lottery         = W5


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

Reset:
  PINS = %00000000                              ' clear all outputs
  DIRS = %00011110                              ' make P0-P5 outputs

  PAUSE 100                                     ' let RC-4 power up
  SEROUT Sio, Baud, ("!RC4", %11, "X")          ' clear RC-4


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

Main:
  timer = 0                                     ' reset timer

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

  timer = 0                                     ' reset
  Fogger = IsOn
  GOSUB Update_RC4

Fuse_Loop:
  RANDOM lottery
  delay = lottery // 51 + 25
  Fuse = IsOn - Fuse                            ' toggle output
  PAUSE delay
  timer = timer + delay
  IF timer < 3000 THEN Fuse_Loop

  Fuse = IsOff
  Fogger = IsOff
  GOSUB Update_RC4

  Audio = IsOn
  AirBlast = IsOn
  Flash = IsOn

  PAUSE 1000
  Audio = IsOff
  AirBlast = IsOff

  PAUSE 2000
  Flash = IsOff

  GOTO Reset


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

Update_RC4:
  SEROUT Sio, Baud, ("!RC4", %11, "S", relays)
  RETURN

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


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

JezzieRose

At first it didn't do anything when I pressed the Trigger -

I changed -

From
DIRS = %00111111                              ' make P0-P5 outputs
To
DIRS = %00011111                              ' make P0-P4 outputs

And then the Trigger worked.

However the Fogger does not go on and the Fuse just goes on for 1 very short on then off.

In my test program, I turned the Fogger on like this -

SEROUT Sio, Baud, ("!RC4", %11, "R", 4, 1)
PAUSE 3000
SEROUT Sio, Baud, ("!RC4", %11, "R", 4, 0)

I not sure how to read the Update_RC4: Subroutine

Any more help would be appreciated.

JonnyMac

Sorry, Jez, you had asked for a non-standard input (P5) and I'm one of those snarky "Hollywood" guys who thinks he can do no wrong (wink) so I didn't test the code. 

The updated version (above) is corrected and tested -- it works.  Do me a favor, please, and move your trigger input to P6 (this is where we normally bring triggers in).
Jon McPhalen
EFX-TEK Hollywood Office

JezzieRose

The Fogger is still not going on.

I need to have the Trigger on p5 for now until I can make a new button, since the one I am using the header on it will not fit on p6 with the RC-4 serial cable on p7.




JezzieRose

I figured it out.

we have the Fogger on K4, I chaged the code to -

SYMBOL  relays          = B0
SYMBOL   K1             =  BIT0
SYMBOL   K2             =  BIT1
SYMBOL   K3             =  BIT2
SYMBOL   Fogger      =  BIT3

and it works now!

I will move the Fogger to K1 if you think it is better to be there.

Thank you very much.

Now to mount everything and build an "Ammo" box to hold everything.


JonnyMac

You can leave it on K4 if you like -- it's great that you sorted that for yourself (now you can start helping me write programs for others as we wind down to Halloween!).
Jon McPhalen
EFX-TEK Hollywood Office

JezzieRose

I wish I could help, but considering this was our very first prop controlled by anything and our very first program I really don't think we are qualified. (wink)

Is this completed project, with pictures and program, something you would like uploaded to the Completed Projects section?

JonnyMac

Sure -- we always love seen the results.  John and I write a lot of code that just gets launched off into cyberspace and we don't know what happens; it's nice to see projects when we can.
Jon McPhalen
EFX-TEK Hollywood Office

JezzieRose

I need some help modifying the program above.  After several tests we would like the Fogger to continue running while the air blast goes off.

I tried to figure it out on my own, but I an having a difficult time with separating the Fogger time from the Fuse_Loop time.

I would like to be able to adjust the time that the Fogger runs and the Air Blast.


Trigger
Fuse - Flickers for 2 seconds
Fog starts at the same time as the Fuse - runs for 4 seconds
Air Blast, Audio and Flash start after the Fuse stops (2 seconds) and continues run for 2 more seconds.

We took the Cannon to a Make and Take yesterday, and everyone really liked it.  They all agreed that the Fogger needs to continue running during the Air Blast becasue too much Fog comes out of the cannon before the Air Blast.

They also really like the Prop-1 and the RC4, they were a big hit with everyone.



JackMan

QuoteAfter several tests we would like the Fogger to continue running while the air blast goes off.



Fuse = IsOff
  Fogger = IsOff
  GOSUB Update_RC4

  Audio = IsOn
  AirBlast = IsOn
  Flash = IsOn

  PAUSE 1000
  Audio = IsOff
  AirBlast = IsOff

  PAUSE 2000
  Flash = IsOff

All you need to do (I think!) is move "Fogger = IsOff" under "AirBlast = IsOff" You can adjust this time with the PAUSE.

JonnyMac

September 20, 2010, 06:29:14 PM #11 Last Edit: September 20, 2010, 06:31:43 PM by JonnyMac
Here's an update with your new timing.  Note that I put time markers in the comments so you can see what's happening, time-wise, as the program runs.  Also note that the Audio output is pulsed for 500 milliseconds to prevent looping.  

' =========================================================================
'
'   File......
'   Purpose...
'   Author....
'   E-mail....
'   Started...
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  Sio             = 7                     ' SETUP = UP; no ULN

SYMBOL  Trigger         = PIN6                  ' SETUP = DN

SYMBOL  Audio           = PIN4
SYMBOL  Flash           = PIN3
SYMBOL  Fuse            = PIN2
SYMBOL  AirBlast        = PIN1


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

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

SYMBOL  Baud            = OT2400


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

SYMBOL  relays          = B0
SYMBOL   K1             =  BIT0
SYMBOL   K2             =  BIT1
SYMBOL   K3             =  BIT2
SYMBOL   Fogger         =  BIT3

SYMBOL  delay           = B2

SYMBOL  timer           = W4
SYMBOL  lottery         = W5


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

Reset:
  PINS = %00000000                              ' clear all outputs
  DIRS = %00011110                              ' make P0-P5 outputs

  PAUSE 100                                     ' let RC4 start
  SEROUT Sio, Baud, ("!RC4", %11, "X")          ' clear RC-4


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

Main:
  timer = 0                                     ' reset timer

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

  timer = 0
  Fogger = IsOn                                 ' (T0.00)
  GOSUB Update_RC4

Fuse_Loop:
  RANDOM lottery
  delay = lottery // 51 + 25
  Fuse = IsOn - Fuse                            ' toggle output
  PAUSE delay
  timer = timer + delay
  IF timer < 2000 THEN Fuse_Loop

  Audio = IsOn                                  ' (T2.00)
  AirBlast = IsOn
  Flash = IsOn

  PAUSE 500
  Audio = IsOff                                 ' (T2.50)

  PAUSE 1500
  relays = IsOff                                ' (T4.00)
  GOSUB Update_RC4
  AirBlast = IsOff
  Flash = IsOff

  GOTO Reset


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

Update_RC4:
  SEROUT Sio, Baud, ("!RC4", %11, "S", relays)
  RETURN

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


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

JezzieRose

Thank you, I understand it now.  I will give it a go and let you know.

JackMan

Jon,
    If I'm looking at your last program right, (and I could be looking wrong  :-\), I think it's missing "Fogger = IsOff"

JonnyMac

  relays = IsOff

... takes care of the fogger.
Jon McPhalen
EFX-TEK Hollywood Office