November 21, 2024, 05:48:39 PM

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.


I would like to know if i changed the right stuff from a BS1 to BS2 Routine

Started by samsam, March 13, 2008, 08:16:39 PM

Previous topic - Next topic

samsam

I would like to use code for BS2 did i do this right

' =========================================================================
'
'   File...... Switcher.BS1
'   Purpose... Uses button on P7 to sequence through outputs
'   Author.... Jon Williams, EFX-TEK
'   E-mail.... jwilliams@efx-tek
'   Started...
'   Updated... 19 JUN 2007
'
'
' {$PBASIC 2.5}
' {$STAMP BS2}
' =========================================================================


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


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


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

  Trigger      PIN   14                    ' SETUP = DN


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

IsOn           CON     1
IsOff          CON     0


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

timer           VAR    Byte                    ' debounce timer
pointer         VAR    Byte                    ' active pin pointer


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

Reset:
  OUTL = %00000000                              ' clear everything
  DIRS = %01111111                              ' P0..P6 are outputs

  pointer = 0


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

Main:
  PAUSE 10                                      ' scan delay
  timer = timer + Trigger * Trigger             ' increment or clear
  IF timer < 10 THEN Main                       ' hold 0.1 s (10 ms x 10)
    timer = 0

Force_Release:
  IF Trigger = IsOn THEN Force_Release

  IF pointer = 8 THEN Reset                     ' done?
    OUTL = %00000000                            ' no; clear last pin
    HIGH pointer                                ' activate current
    pointer = pointer + 1                       ' point to next
    GOTO Main


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


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


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


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


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


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


' -----[ EEPROM Data ]-----------------------------------------------------
Sam

I Want  Thank You for All Of Your Time And Help

...............In Helping Getting Thing To Work........

JonnyMac

Did you try it?  That's really the best way to learn, you know.  In the future we should all try our own programs before posting and asking others for input.

I did try the program, and good news: it works.  The BS2 has a more advanced version of PBASIC than the BS1, so here's how I'd normally code it:

' =========================================================================
'
'   File...... Switcher.BS2
'   Purpose... Uses button on P7 to sequence through outputs
'   Author.... Jon Williams, EFX-TEK
'   E-mail.... jwilliams@efx-tek
'   Started...
'   Updated... 19 JUN 2007
'
'   {$PBASIC 2.5}
'   {$STAMP BS2}
'
' =========================================================================


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


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


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

Trigger         PIN     14                        ' SETUP = DN


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

IsOn            CON     1
IsOff           CON     0


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

timer           VAR     Byte                    ' debounce timer
pointer         VAR     Byte                    ' active pin pointer


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

Reset:
  OUTL = %00000000                              ' clear everything
  DIRS = %01111111                              ' P0..P6 are outputs

  pointer = 0


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

Main:
  PAUSE 10                                      ' scan delay
  timer = timer + 10 * Trigger                  ' increment or clear
  IF timer < 50 THEN Main                       ' hold 0.05 s
    timer = 0

Force_Release:
  IF Trigger = IsOn THEN Force_Release

  OUTL = %00000000                              ' clear last pin
  IF ( pointer < 8 ) THEN                       ' still active?
    HIGH pointer                                ' yes, light led
    pointer = pointer + 1
  ELSE
    GOTO Reset                                  ' no, clear and reset
  ENDIF

  GOTO Main
Jon McPhalen
EFX-TEK Hollywood Office