November 23, 2024, 05:26:53 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.


A Simple Code...A Brain in Knots....

Started by botag, November 15, 2008, 09:31:02 PM

Previous topic - Next topic

botag

So I'm a mechanics kind of guy....not a code writer...Although, with a little patience, I am making programming progress. But I've hit a wall....Here's the thing;
I need a program that I can have the Prop-1 execute while on my bench testing my mechanics...I have a push button trigger that I would like to use to activate. One press=rod out....Next press=rod in....Below is the mess I came up with...Is it worth saving...can you whip up something more simple...???

thanks
Steve Battaglia

PS - I love your products...(even if I can't get the relay board special deal anymore.... ;)) KEEP IT UP !!!

botag

Will the cylinder retract even after the first Solenoid=IsOn....Or does it wait for the second button push.....I need it to wait for the second activation before retracting....possible???

THX
SB

botag

November 15, 2008, 10:18:40 PM #2 Last Edit: November 15, 2008, 10:20:46 PM by JonnyMac
Sorry...forgot the code...here it is....

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


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


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


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

SYMBOL  Trigger         = PIN6                  ' SETUP = DN
SYMBOL  Solenoid        = PIN1                  ' OUT1/V+



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

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


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

SYMBOL  timer           = B2


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

Reset:
  PINS = %00000000                              ' clear all
  DIRS = %00000011                              ' set outputs

  PAUSE 1000                                    ' let CAP initialize


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

Main:
  timer = 0                                     ' reset timer

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

  Solenoid = IsOn


  PINS = %00000000                              ' clear all
  DIRS = %00000011                              ' set outputs

  timer = 0                                     ' reset timer


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

  Solenoid = IsOff

GOTO main

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


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


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

BigRez

November 15, 2008, 10:32:40 PM #3 Last Edit: November 15, 2008, 10:37:44 PM by bigrez
There a nice TOGGLE feature which will do exactly what you need, if I understand correctly:


' =========================================================================
'   {$STAMP BS1}
'   {$PBASIC 1.0}
' =========================================================================

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

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

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

SYMBOL  Sio             = 7                     ' SETUP = out; no ULN
SYMBOL  Trigger         = PIN6                  ' SETUP = DN

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

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

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

Reset:
  PINS = %00000000                              ' clear all outputs
  DIRS = %00000001                              ' make P0 an output

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

Main:
  PAUSE 5                                 ' loop pad
  IF Trigger = 0 THEN Main                ' wait trigger input

  TOGGLE 0                                ' reverse pin 0 I/O direction
  PAUSE 1000
  GOTO Main


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


You may have to adjust the wait between toggling the cylinder.  Give this a try with your trainer.  If the 1 second pause doesn't work for you, you can add code which detects when the biutton is released.

JonnyMac

November 15, 2008, 10:37:32 PM #4 Last Edit: November 15, 2008, 11:00:36 PM by JonnyMac
Rule #1: Don't put my name on your programs -- I don't want credit for your good stuff ( or bad!  ;) )
Rule #2: Make small mods to working programs and test each small change -- this will help prevent brain meltdowns
Rule #3: Believe that we say what we mean and mean what we say: the RC-4+4 was a limited quantity offer and we sold out quickly

Okay, I see that BigRez answered as I was typing and he has it correct: PBASIC has a TOGGLE instruction that will make a pin an output and flip its state (on if it was off; off if it was on).  My only grief with BigRez's version is that the input is not debounced and this is a pretty big no-no in real-world prop control.  Debouncing prevents false positives and you should do it (I have it built into my standard template).

Here's my version:

' =========================================================================
'
'   File...... Toggler.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... 15 NOV 2008
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  Trigger         = PIN6                  ' SETUP = DN
SYMBOL  Control         = 0


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

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

SYMBOL  Yes             = 1
SYMBOL  No              = 0


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

SYMBOL  timer           = B2


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

Reset:
  PINS = %00000000                              ' clear all
  DIRS = %00000001                              ' set output(s)


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

Main:
  timer = 0                                     ' reset timer

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

  TOGGLE Control                                ' flip output state
  PAUSE 900                                     ' prevent output oscillation

  GOTO Main


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


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

BigRez

Jon - my bad... I thought the debouncing was only needed when using a PIR trigger.  Perhaps this is elementary electronics, but how could a push-button trigger send a false positive?

Rule #4:  Jon is wise...

:)

JonnyMac

November 15, 2008, 10:58:01 PM #6 Last Edit: November 16, 2008, 10:05:53 AM by JonnyMac
The problem is not with the button, but the wires -- which can become big antennas -- connecting it to the board can.  We've seen this in myriad applications where someone keys a walkie-talkie and a prop starts up.  Electrical noise on the input is easily defeated with simple debouncing and should be done all the time; it saves a lot of troubleshooting headaches.
Jon McPhalen
EFX-TEK Hollywood Office

botag

sorry Jon.....I had borrowed about 85% of that code from a little ditty you had written for someone else....you're right though,,I'll remove all names from here on out...Didn't know about the Toggle command, thanks go out to you and BigRez...Can't wait to try it out.....

SB