November 23, 2024, 06:10:03 AM

News:

Got VSA?  Want to use your Prop-SX?  Now you can!  See the VSA section of the Library forum for Prop-SX code that works with VSA.


Trigger not starting my event code

Started by reddragon, October 17, 2009, 06:23:03 PM

Previous topic - Next topic

reddragon

I think that all is good in the code but when i hit the mat switch notting happens here is what i have

led is on
matsw is hit
sound plays
sound stops
led is off
yard led is on
fwd one sound
release
go to main

This is what i have;

' =========================================================================
'
'   File......prop code for 2009
'   Purpose... Halloween 2009
'   Author....Chris self
'   E-mail....
'   Started...
'   Updated...
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


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


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


' -----[ I/O Definitions ]-------------------------------------------------
led             PIN     12
jumper          PIN     10
yardled         PIN     14
Trigger         PIN     15
sound           PIN      8                      ' play audio
fwd             PIN      0                      ' forward one clip
' -----[ Constants ]-------------------------------------------------------

IsOn            CON     1                       ' for active-high in/out
IsOff           CON     0
isyes           CON     1
isno            CON     0


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




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

Reset:
  OUTH = %00000000 : OUTL = %00000000           ' clear all outputs
  DIRS = %01011101 : DIRH = %00000001           ' set outputs


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

Main:
  LOW 14                                        ' yard led off
  IF trigger = isoff  THEN main
  HIGH 12                                       ' led on
  sound = ison                                  ' start clip
  PAUSE 200                                     ' play
  sound = isoff                                 ' stop
  PAUSE 1500                                    ' wait
  LOW 12                                        ' led off
  HIGH 14                                       ' yard led on
  fwd = ison                                    ' fwd one track
  PAUSE 10
  fwd = isoff                                   ' release


  GOTO main




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


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


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


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


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


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


JonnyMac

Sorry, the code is not good... a lot of problems here:

1) Please consider reading and following "The Elements of PBASIC Style" (in the online help file)
     -- it will help make your programs less buggy

2) If you're going to name pins, use the names in the code -- give up HIGH and LOW with pin number (hard to follow)

3) You should always debounce sensor inputs.  Always.

I've taken my stock Prop-2 template and put a proper version of your program in it.  If you look very closely you'll see that you hosed up the DIRS assignment and you didn't have some pins set as outputs (this may have cause you to try HIGH and LOW).  If you look at my listing you'll see that DIRS is broken up into DIRH (for P15..P8) and DIRL (for P7..P0); in your program the first assignment (using DIRS) is actually working on DIRL when you intend it to work on DIRH.  The effect is that you swapped the DIRH and DIRL assignments from what you actually want.

Lesson: Don't messy with JonnyMac's templates! -- they rock as is!   ;D  Just fill in the blanks to creat your program.   ;)

Note: I extend the pulse to the forward button because I don't thing 10ms is going to be long enough based on working with that chip.  And you do realize, that the YardLED is only one while you're "pressing" the FWD button, right?   Maybe that's what you want.  I also changed "Sound" to "SoundFX" because SOUND is a PBASIC1 keyword -- it's very bad form to use keywords in code listings that may port from one processor to another.

' =========================================================================
'
'   File......
'   Purpose...
'   Author....
'   E-mail....
'   Started...
'   Updated... 17 OCT 2009
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


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


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


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

Trigger         PIN     15                      ' SETUP = DN
YardLed         PIN     14                      ' SETUP = DN or out
Led             PIN     12                      ' SETUP = DN or out
Jumper          PIN     10
SoundFX         PIN      8                      ' start audio
Fwd             PIN      0                      ' forward one clip


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

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

Yes             CON     1
No              CON     0


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

timer           VAR     Word


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

Reset:
  OUTH = %00000000 : OUTL = %00000000           ' preset IOs
  DIRH = %01011101 : DIRL = %00000001           ' set output pins


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

Main:
  YardLed = IsOff

Check_Trigger:
  timer = 0
  DO WHILE (timer < 100)
    PAUSE 5
    timer = (timer + 5) * Trigger
  LOOP

  Led = IsOn

  SoundFX = IsOn
  PAUSE 200
  SoundFX = IsOff
  PAUSE 1500

  Led = IsOff
  YardLed = IsOn
  Fwd = IsOn
  PAUSE 50
  Fwd = IsOff

  GOTO Main


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


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


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


Jon McPhalen
EFX-TEK Hollywood Office