November 24, 2024, 09:59:09 PM

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.


Need help getting started with a switch and code question

Started by ChrisV2, September 19, 2012, 09:01:21 PM

Previous topic - Next topic

ChrisV2

Hello,

Please forgive me but I'm a starting programmer with this... We are using a Prop1 Controller and want to use it to control a servo that will release a flame. The trick is that we want the flame to be "on" as long as the switch is depressed.

Obviously we're not using a PIR or pressure mat, but a "switch as yet to be determined" from what I'm being told by the guy that does all the hard work in building all the physical stuff!! If you have any suggestions, please feel free to share!! We're envisioning some sort of pedal that an actor presses to shoot the flame. When he steps off it, the flame goes out.

Having said all that, "my" real question is how do I get started with the code on the Prop1 Controller? Does anyone have any basic example code they might give me to get me started? Any help would be GREATLY appreciated!!

Thanks,
Chris

JonnyMac

We have a PDF on the Prop-1 page (main site) that will be helpful.

And, here's your program. It won't be obvious at first but will ultimately sink in.

Your button will connect between the P6.W (white) and P6.R (red) connections. The easiest way to make a connection is to buy an extender cable and cut it in half; the hard-part of the 3-pin female connector is done.  Connect your servo to the P0 header -- be mindful of the WRB (white-red-black) connections.

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


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


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


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

SYMBOL  Trigger         = PIN6                  ' SETUP = DN

SYMBOL  Servo           = 0                     ' Use P0 servo header


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

SYMBOL  Yes             = 1
SYMBOL  No              = 0

SYMBOL  TrOn            = 1                     ' active-high trigger
SYMBOL  TrOff           = 0

SYMBOL  IsOn            = 1                     ' active-high I/O
SYMBOL  IsOff           = 0


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

SYMBOL  timer           = B2                    ' for debounce loop
SYMBOL  pos             = B3


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

Reset:
  PINS = %00000000                              ' all off
  DIRS = %00111111                              ' P5..P0 are outputs

  pos = 200                                     ' start on one side


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

Main:
  timer = 0                                     ' reset debounce timer

Check_Trigger:
  PAUSE 20                                      ' scan delay
  PULSOUT Servo, pos                            ' update
  IF Trigger = TrOff THEN Main                  ' check trigger input
    timer = timer + 5                           ' update timer
  IF timer < 100 THEN Check_Trigger             ' check timer

  pos = 100                                     ' swing to other side

Light_It:
  PAUSE 20
  PULSOUT Servo, pos                            ' refresh
  IF Trigger = TrOff THEN Reset                 ' button released
    GOTO Light_It                               ' no, keep holding


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


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


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

ChrisV2

Hey Jon!!

Thanks SOOO much for the coding example. This will get me started. Won't be able to touch it until Saturday morning, but at least not I've got a great place to start from.

One final question though... What if we wanted to shoot fire from 8 different outputs? I could still do that using the PROP1 controller, right? I would just do the following under the Reset section, right?

DIRS = 111111111                              ' P7 - P0 are outputs

Thanks again Jon!!

JonnyMac

Using one servo is easy, using multiple is not.  And if you want to control eight servos you hae to use power-on instead of a trigger button.  Please clarify what you want to do.

Something important to remember about servos: they MUST be refreshed every 20-30ms or they can stutter and lose their position.  The Prop-1 is not very good at servo control (the HC-8+ is).
Jon McPhalen
EFX-TEK Hollywood Office

JackMan

ChrisV2,
The Prop-1 is a great little controller and you can never have too many of them on hand. It is also capable of some pretty amazing programs for it's size but I'm just wondering why you would need a micro controller for a simple on/off function when basically your "foot switch" is doing the job. Also not sure why you even need the servo. What is the servo turning on?

ChrisV2

Ok, you guys are going to hate me but I might have mis-typed when I wrote servo. Should I have said Solenoid? To be honest, I'm not on-site yet and don't know what the physical layout past the PROP1 controller will be. I know they've manually tested the flame burst part.

The only thing I was told was they wanted something to shoot a flame for as long as the switch was being pressed. Late yesterday it  changed to be that they now want to shoot 8 different flames out at different intervals. I'm pretty sure I can activate what ever I need to on the 8 outputs, hopefully, but I haven't done anything with an "active while pressed switch". Then the idea of a foot pedal came up and that's what they agreed they wanted.

If it were just one flame burst or all 8 at the same time, your right... I we wouldn't need a controller, but they wanted the bursts to be random "while" the pedal was being pressed.

Sorry guys...

ChrisV2

Awesome, Awesome, Awesome Jon!!

Thanks SO much!!

I'll be putting this on a controller first thing Saturday morning and will hopefully be done with all the tweaking before dinner!!!

Thank you very much!!

Chris

JonnyMac

Okay... the root of "specification" is "specific," and in these matters, specifics count.

The good new is that it's far easier to control solenoids that servos.  The bad news is that you only have eight IO points on the controller, so you have a trigger and seven outputs. No working around it if you want random behavior.

Specifics...

Q: How many outputs are on at the same time?
Q: How long is the output supposed to be on?
     -- or does it go off if randomly selected to go off (in case of multiple outputs)
Q: If it's just one at a time ("one-shotting") how long is the output on?
Q: Is there any delay between outputs being activated?

In most cases writing and embedded program is fairly easy once you know exactly what is supposed to happen. So... dish the details. ;)
Jon McPhalen
EFX-TEK Hollywood Office

JonnyMac

Note that I took down that program -- confused it with another; please answer the questions above and I'll re-post with the corrections.
Jon McPhalen
EFX-TEK Hollywood Office

JackMan

Here's a quick program that will give you random firing of all 8 outputs when power is supplied to the Prop-1 with your foot switch. Note there is no trigger in the code. The valves will fire in random sequence, in random quantities, and in random durations for as long as your foot switch is held. Also note the possibility of relays needed.

' =========================================================================
'
'   File...... Random Fire
'   Purpose...
'   Author.... JackMan
'   E-mail....
'   Started... 9/21/12
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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

' Random firing of 8 valves (OUT0 - OUT7) when power is supplied to Prop-1 (foot switch)
' will continue until power is disconnected from Prop-1 (foot switch)
' total amperage draw (mA) of ALL solenoids MUST be within Prop-1 specs or relays will be needed
' random valve ON times are adjustable by changing the PULSE_MIN and PULSE_MAX values

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


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




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

SYMBOL  PULSE_MIN        = 250                  ' min valve delay
SYMBOL  PULSE_MAX       = 1000                 ' max valve delay

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

SYMBOL  valves          = B2
SYMBOL  last              = B3

SYMBOL  delay           = W3
SYMBOL  timer           = W4
SYMBOL  lottery         = W5

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

Reset:
  PINS = %00000000                              ' clear all outputs
  DIRS = %11111111                              ' make P0-P7 outputs


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

Main:
Light_Em_Up:
  RANDOM lottery
  valves = lottery & %11111111
  IF valves = last THEN Light_Em_Up             ' force change
    last = valves
  PINS = PINS & %00000000 | valves              ' update valve outputs

  RANDOM lottery
  delay = PULSE_MAX - PULSE_MIN + 1
  delay = lottery // delay + PULSE_MIN          ' caculate delay
  TOGGLE valves
  PAUSE delay
  GOTO Main

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

ChrisV2

Hey Jon,

Specifics...

Q: How many outputs are on at the same time?
A: No more than one at a time but we would like to use all 8 outputs.
    The good news is that they don't want it to be random now, but a static sequence of output 0,7,3,2,5,4,6,1

Q: How long is the output supposed to be on?
     -- or does it go off if randomly selected to go off (in case of multiple outputs)
A: They would like the output to be "on" as long as the switch is closed. Obviously it would have to complete the current cycle before checking the switch status again.

Q: If it's just one at a time ("one-shotting") how long is the output on?
A: We're thinking that the flame should be on for 0175 ms.

Q: Is there any delay between outputs being activated?
A: A pause of 0175 ms between each of the 8 firing.


Below is our code. Right now we're simulating a switch by shorting the Red/White wires from P6 on the PROP1 controller.

Our problem comes in where output 6 fires as soon as the Red and White wire is crossed. Even though it fires I can see from the debug statements below that we haven't even gotten down into the firing part of the code... it was still checking the Trigger!! I really don't know where that firing is coming from.

We don't have internet access where we're working on this piece, so I'm making a run to the office to get internet access to ask for help.

Also, if we keep the Red/White wires crossed nothing fires off from the PROP1 controller, but I can see from the debug statements where the code is executing properly.

Are we trying to get this to do something it can't.

I "briefly" looked into moving all this to a PROP2 controller, but quickly realized I was going to have to rewrite this program with different syntax. It was giving me a lot of errors when I tried to save the program (previously saved as a BS2 program) to the PROP2 controller...

So we're stuck... please help?


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


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


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


' -----[ I/O Definitions ]-------------------------------------------------
SYMBOL  Flame jet1     = 0                     ' Flame jet1 on OUT0
SYMBOL  Flame jet2     = 1                     ' Flame jet2 on OUT1
SYMBOL  Flame jet3     = 2                     ' Flame jet3 on OUT2
SYMBOL  Flame jet4     = 3                     ' Flame jet4 on OUT3
SYMBOL  Flame jet5     = 4                     ' Flame jet5 on OUT4
SYMBOL  Flame jet6     = 5                     ' Flame jet6 on OUT5
SYMBOL  Flame jet7     = 6                     ' Flame jet7 on OUT6
SYMBOL  Flame jet8     = 7                     ' Flame jet8 on OUT7

SYMBOL  Trigger              = PIN6                  ' Setup = DN

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

SYMBOL  Yes             = 1
SYMBOL  No              = 0

SYMBOL  TrOn            = 1                     ' Active-High I/O
SYMBOL  TrOff           = 0                     '

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


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

SYMBOL  timer           = B2                    ' For Debounce Loop
SYMBOL  thePin          = B3                    ' Current Output Pin
SYMBOL  lastPin         = B4                    ' Last Output Activated

SYMBOL  lottery         = W5                    ' random value

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

Reset:
  PINS = %00000000                              ' clear all
  DIRS = %11111111                              ' Make all outputs active


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

Main:
  timer = 0                                     ' Reset Timer

Check_Trigger:
'  PAUSE 5                                       ' Scan Delay
  DEBUG "Checking trigger "
  IF Trigger = TrOff THEN Main                  ' Check Trigger Input
    DEBUG "Trigger tripped "
    timer = timer + 5                           ' Update Timer
  IF timer < 5 THEN Check_Trigger             ' Check timer

Activate_Flame:

  HIGH Flame jet1                         ' Start air Flame jet1
  DEBUG "Flame Burst  1 - "
  PAUSE 0175                                    ' Hold for .5 seconds
  LOW Flame jet1                          ' Stop Flame jet1
  DEBUG "Pausing..."
  PAUSE 0175                                    ' Hold for .5 seconds

  HIGH Flame jet8                         ' Start air Flame jet1
  DEBUG "Flame Burst  8 - "
  PAUSE 0175                                    ' Hold for .5 seconds
  LOW Flame jet8                          ' Stop Flame jet1
  DEBUG "Pausing..."
  PAUSE 0175                                    ' Hold for .5 seconds

  HIGH Flame jet4                         ' Start air Flame jet1
  DEBUG "Flame Burst  4 - "
  PAUSE 0175                                    ' Hold for .5 seconds
  LOW Flame jet4                          ' Stop Flame jet1
  DEBUG "Pausing..."
  PAUSE 0175                                    ' Hold for .5 seconds

  HIGH Flame jet3                         ' Start air Flame jet1
  DEBUG "Flame Burst  3 - "
  PAUSE 0275                                    ' Hold for .5 seconds
  LOW Flame jet3                          ' Stop Flame jet1
  DEBUG "Pausing..."
  PAUSE 0175                                    ' Hold for .5 seconds

  HIGH Flame jet6                         ' Start air Flame jet1
  DEBUG "Flame Burst  6 - "
  PAUSE 0275                                    ' Hold for .5 seconds
  LOW Flame jet6                          ' Stop Flame jet1
  DEBUG "Pausing..."
  PAUSE 0175                                    ' Hold for .5 seconds

  HIGH Flame jet5                         ' Start air Flame jet1
  DEBUG "Flame Burst  5 - "
  PAUSE 0275                                    ' Hold for .5 seconds
  LOW Flame jet5                          ' Stop Flame jet1
  DEBUG "Pausing..."
  PAUSE 0175                                    ' Hold for .5 seconds

  HIGH Flame jet7                         ' Start air Flame jet1
  DEBUG "Flame Burst  7 - "
  PAUSE 0175                                    ' Hold for .5 seconds
  LOW Flame jet7                          ' Stop Flame jet1
  DEBUG "Pausing..."
  PAUSE 0175                                    ' Hold for .5 seconds

  HIGH Flame jet2                         ' Start air Flame jet1
  DEBUG "Flame Burst  2 || "
  PAUSE 0175                                    ' Hold for .5 seconds
  LOW Flame jet2                          ' Stop Flame jet1
  DEBUG "Pausing..."
  PAUSE 0175                                    ' Hold for .5 seconds

  GOTO Main                                     ' start over


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


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


' -----[ User Data ]-------------------------------------------------------


ChrisV2

Hey Jon,

One final note. Because we haven't used a PROP2 controller before, we were hesitant to start that learning curve.

But... if it's as easy as porting our code over to it with a few minor changes and it'll work as we'd hoped, then we're game!!

As a side note on the actual PROP2 controller, we took your class a few years ago at the Dallas haunt convention and made some notes that we were supposed to modify the PROP1 board before using it. Is that something that needs to be done on the PROP2 Controller?

JonnyMac

Prop-1 code will not run on the Prop-2 without updating?  Do you have a Prop-2? If yes, start a new thread in that forum and I will write a really clean bit of code for you.

Please, please please, for the love of God and all that is Holy (I'm I convincing you that I begging here? <grin>)... understand that with the Prop-1 you cannot have a sensor input if you're going to use eight outputs.  The pins on a controller are called IO for input-output.  That is, input OR output, but the cannot be both at the same time.  If you use one of the pins as an input that trigger will activate the solenoid connected to the related pin (OUT6 in your case).

With the Prop-2 these problems go way because we have more IO.  Programming is a little easier in some cases, too.
Jon McPhalen
EFX-TEK Hollywood Office

JackMan

Here's a very simple way of doing what you requested with the Prop-1. Just use your "foot switch" to provide power to the Prop-1 and you don't need an input for a trigger. This will loop thru all 8 outputs in order from 0 -7 so just wire your solenoid connections to fit the specific valve order you want, 0,7,3,2,5,4,6,1
valve #1 connects to OUT0, valve #8 connects to OUT1, valve #4 connects to OUT2, valve #3 connects to OUT3, etc.
Also your code has 0175 as the delay but your notation says .5 second. A .5s delay would be a value of 500, not 0175.


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


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


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


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




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

SYMBOL  ValveTime       = 500                   ' .5s valve delay time

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

SYMBOL  ThePin          = B2                    ' pin pointer


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

Reset:
  PINS = %00000000                              ' clear all outputs
  DIRS = %11111111                              ' make P0-P7 outputs


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

Main:
   FOR ThePin = 0 TO 7                          ' loop through Valves
    HIGH ThePin                                 ' Valve on
    PAUSE ValveTime                             ' hold
    LOW ThePin                                  ' Valve off
    PAUSE ValveTime                             ' hold
   NEXT
   GOTO Main


JonnyMac

Here's a variation on Jack's code that lets you rewire in software.  The order is determined by the table at Sequence

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


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


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


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


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

SYMBOL  OnTime          = 500                   ' .5s valve delay time
SYMBOL  OffDelay        = 500


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

SYMBOL  idx             = B2                    ' sequence index
SYMBOL  thePin          = B3


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

Reset:
  PINS = %00000000                              ' clear all outputs
  DIRS = %11111111                              ' make P0-P7 outputs


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

Main:
  FOR idx = 0 TO 7                              ' loop through outputs
    READ idx, thePin                            ' adjust order
    HIGH thePin                                 ' activate
    PAUSE OnTime                                ' hold on
    LOW thePin                                  ' de-activate
    PAUSE OffDelay                              ' hold off
  NEXT
  GOTO Main


' -----[ User Data ]-------------------------------------------------------

Sequence:
  EEPROM (0, 7, 3, 2, 5, 4, 6, 1)
Jon McPhalen
EFX-TEK Hollywood Office