May 17, 2024, 03:18:31 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.


Working with RC-4

Started by tds234, September 12, 2007, 09:48:41 PM

Previous topic - Next topic

tds234

I've got the basic code that Jon rewrote, but I was trying to the get RC-4 to work serially since I got my crystals from Parallax. I've got the 20 Mhz crystal installed and the following code but cannot get the RC-4 to switch anything on...see the AmbientLightOn sub routine for the basic thing I'm trying to get to work.

' =========================================================================
'
'   File...... TDS3.SXB
'   Purpose...
'   Author.... TDS -- updated by Jon Williams, EFX-TEK
'   E-mail....
'   Started...
'   Updated...
'
' =========================================================================


' -------------------------------------------------------------------------
' Program Description
' -------------------------------------------------------------------------


' -------------------------------------------------------------------------
' Conditional Compilation Symbols
' -------------------------------------------------------------------------


' -------------------------------------------------------------------------
' Device Settings
' -------------------------------------------------------------------------

'DEVICE          SX28, OSC4MHZ, TURBO, STACKX, OPTIONX, BOR42
'FREQ            4_000_000
DEVICE          SX28, OSCXT2, TURBO, STACKX, OPTIONX, BOR42
FREQ            20_000_000

ID              "TDS3"


' -------------------------------------------------------------------------
' I/O Pins
' -------------------------------------------------------------------------

AlarmLed        PIN     RB.0 OUTPUT
SensorLed       PIN     RB.5 OUTPUT
Trigger         PIN     RB.6 INPUT
Sio             PIN     RC.7                    ' no SETUP, no ULN

RedLight1       PIN     RC.0 OUTPUT
RedLight2       PIN     RC.1 OUTPUT
Motor1          PIN     RC.2 OUTPUT
Motor2          PIN     RC.6 OUTPUT
Strobe          PIN     RC.3 OUTPUT
Popper          PIN     RC.4 OUTPUT
AmbientLights   PIN     RC.5 OUTPUT
MusicTrigger    PIN     RC.7 OUTPUT


' -------------------------------------------------------------------------
' Constants
' -------------------------------------------------------------------------

BlinkDelay      CON     250                     ' blink rate
BlinkFast       CON     100
Timeout         CON     1000
Bumpstart       CON     50

IsOn            CON     1
IsOff           CON     0

BaudMode        CON     "OT38400"

' -------------------------------------------------------------------------
' Variables
' -------------------------------------------------------------------------

lottery         VAR     Byte                    ' random value
check           VAR     Byte
idx             VAR     Byte
bumper          VAR     Byte

tmpB1           VAR     Byte                    ' for subs/funcs
tmpB2           VAR     Byte
tmpW1           VAR     Word


' =========================================================================
  PROGRAM Start
' =========================================================================


' -------------------------------------------------------------------------
' Subroutine / Function Declarations
' -------------------------------------------------------------------------

DELAY_MS        SUB     1, 2                    ' delay in milliseconds
ALL_OFF         SUB     0
WAKE_UP         SUB     0
PLAY_MUSIC      SUB     0
RND_ACTIVITY    SUB     1
RX_BYTE         FUNC    1, 0                    ' receive a byte
TX_BYTE         SUB     1                       ' transmit a byte
TX_STR          SUB     2                       ' transmit a string
AmbientLightsOn SUB   0

' -------------------------------------------------------------------------
' Program Code
' -------------------------------------------------------------------------

Start:
  MusicTrigger = IsOff
  AlarmLed = IsOff
  Popper = IsOff
  SensorLed = IsOff
  'AmbientLights = IsOff

  DELAY_MS 1000
  AmbientLightsOn


  ALL_OFF
  DELAY_MS 5000
  WAKE_UP

  'warm up sensor
  SensorLed = IsOn
  DELAY_MS 30_000
  SensorLed = IsOff

Setup:
  AmbientLights = IsOn

Main:
  DO WHILE Trigger = IsOff
    RANDOM lottery
    DELAY_MS BlinkDelay
    AlarmLed = ~AlarmLed                        ' toggle LED
    IF bumper = 0 THEN
      RND_ACTIVITY lottery
    ELSE
      DEC bumper
    ENDIF
  LOOP

  AlarmLed = IsOff
  RANDOM lottery                          ' seed it again

Act_1:
  PLAY_MUSIC
  RedLight1 = IsOn
  RedLight2 = IsOn
  DELAY_MS 11_000
  ALL_OFF

Act_2:
  FOR idx = 1 TO 75
    RedLight1 = ~RedLight1                      ' toggle
    RedLight2 = RedLight1                       ' follow #1
    check = idx // 5
    IF check = 0 THEN
      Motor1 = ~Motor1
    ENDIF
    DELAY_MS BlinkDelay
  NEXT
  ALL_OFF

Act_3:
  RedLight1 = IsOn
  Motor1 = IsOn
  ' Motor2 = IsOn
  FOR idx = 1 TO 75
    RedLight1 = ~RedLight1                      ' toggle
    RedLight2 = ~RedLight1                      ' opposite of #1
    DELAY_MS BlinkFast
  NEXT
  All_OFF   

Act_4:                                          ' the payoff
  AmbientLights = IsOff
  DELAY_MS 250
  Strobe = IsOn
  DELAY_MS 2000
  Popper = IsOn
  DELAY_MS 100
  Popper = IsOff
  DELAY_MS 2000
  ALL_OFF

Reset_Show:
  DELAY_MS 1000
  AlarmLed = IsOn
  AmbientLights = IsOn
  DELAY_MS 10_000
  bumper = BumpStart

  GOTO Main


' -------------------------------------------------------------------------
' Subroutine / Function Code
' -------------------------------------------------------------------------

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

' Use: byteVal = RX_BYTE
' -- receive "byteVal" at "BaudMode" on pin "Sio"

FUNC RX_BYTE
  SERIN Sio, BaudMode, tmpB1
  RETURN tmpB1
  ENDFUNC

' -------------------------------------------------------------------------
SUB AmbientLightsOn
TX_STR "!!!!!!"
TX_STR "!RC4"
TX_BYTE %11
TX_BYTE "R"
TX_BYTE 3
TX_BYTE 1
ENDSUB

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

' Use: TX_BYTE byteVal
' -- transmit "byteVal" at "BaudMode" on pin "Sio"

SUB TX_BYTE
  SEROUT Sio, BaudMode, __PARAM1
ENDSUB

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

' Use: TX_STR [string | label]
' -- "string" is an embedded string constant
' -- "label" is DATA statement label for stored z-String

SUB TX_STR
  tmpW1 = __WPARAM12                            ' get address of string
  DO
    READINC tmpW1, tmpB1                        ' read a character
    IF tmpB1 = 0 THEN EXIT                      ' if 0, string complete
    TX_BYTE tmpB1                               ' send character
  LOOP
  ENDSUB

' Use: DELAY_MS milliseconds

SUB DELAY_MS
  IF __PARAMCNT = 1 THEN
    tmpW1 = __PARAM1
  ELSE
    tmpW1 = __WPARAM12
  ENDIF
  PAUSE tmpW1
  ENDSUB

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

SUB ALL_OFF
  RedLight1 = IsOff
  RedLight2 = IsOff
  Motor1 = IsOff
  Motor2 = IsOff
  Strobe = IsOff
  Popper = IsOff
  ' AmbientLights = IsOff
  ENDSUB

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

SUB WAKE_UP
  Strobe = IsOn
  DELAY_MS 2000
  Strobe = IsOff
 
  DELAY_MS 2000

  AmbientLights = IsOn
  DELAY_MS 2000
  AmbientLights = IsOff
 
  DELAY_MS 2000

  Motor1 = IsOn
  DELAY_MS 4000
  Motor1 = IsOff
 
  DELAY_MS 2000

  Motor2 = IsOn
  DELAY_MS 4000
  Motor2 = IsOff
 
  DELAY_MS 2000

  Redlight1 = IsOn
  DELAY_MS 4000
  Redlight1 = IsOff
 
  DELAY_MS 2000

  Redlight2 = IsOn
  DELAY_MS 4000
  Redlight2 = IsOff
 
  DELAY_MS 2000

  PLAY_MUSIC

  ENDSUB

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

SUB PLAY_MUSIC
  MusicTrigger = IsOn
  DELAY_MS 50
  MusicTrigger = IsOff
  ENDSUB

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

' Use: RND_ACTIVITY seed
' -- seed should be randomized before calling

SUB RND_ACTIVITY
  tmpB1 = __PARAM1
  tmpB2 = tmpB1 // 100

  IF tmpB2 = 0 THEN
     SensorLed = IsOn
     DELAY_MS 250
     SensorLed = IsOff

    tmpB2 = tmpB1 // 5

    IF tmpB2 = 0 THEN
      Motor1 = IsOn
      DELAY_MS 2000
      Motor1 = IsOff
    ENDIF

    IF tmpB2 = 1 THEN
      Motor2 = IsOn
      DELAY_MS 2000
      Motor2 = IsOff
    ENDIF

    IF tmpB2 = 2 THEN
      RedLight1 = IsOn
      DELAY_MS 2000
      RedLight1 = IsOff
    ENDIF

    IF tmpB2 = 3 THEN
      RedLight2 = IsOn
      DELAY_MS 2000
      RedLight2 = IsOff
    ENDIF

    IF tmpB2 = 4 THEN
      Strobe = IsOn
      DELAY_MS 2000
      Strobe = IsOff
    ENDIF

    bumper = BumpStart                          ' reset timer
  ENDIF
  ENDSUB


' -------------------------------------------------------------------------
' User Data
' -------------------------------------------------------------------------

JonnyMac

Here's a generic RC-4 demo -- make sure it works first, then fold the subroutines into your code as needed.

' =========================================================================
'
'   File...... RC-4_Demo.SXB
'   Purpose...
'   Author.... Jon Williams, EFX-TEK
'   E-mail.... jwilliams@efx-tek.com
'   Started...
'   Updated...
'
' =========================================================================


' -------------------------------------------------------------------------
' Program Description
' -------------------------------------------------------------------------


' -------------------------------------------------------------------------
' Conditional Compilation Symbols
' -------------------------------------------------------------------------


' -------------------------------------------------------------------------
' Device Settings
' -------------------------------------------------------------------------

DEVICE          SX28, OSCXT2, TURBO, STACKX, OPTIONX, BOR42
FREQ            20_000_000
ID              "RC4_Demo"


' -------------------------------------------------------------------------
' I/O Pins
' -------------------------------------------------------------------------

Sio             PIN     RC.7


' -------------------------------------------------------------------------
' Constants
' -------------------------------------------------------------------------

IsOn            CON     1
IsOff           CON     0

BaudMode        CON     "OT38400"


' -------------------------------------------------------------------------
' Variables
' -------------------------------------------------------------------------

relays          VAR     Byte

tmpB1           VAR     Byte                    ' for subs/funcs
tmpB2           VAR     Byte
tmpW1           VAR     Word


' =========================================================================
  PROGRAM Start
' =========================================================================


' -------------------------------------------------------------------------
' Subroutine / Function Declarations
' -------------------------------------------------------------------------

DELAY_MS        SUB     1, 2                    ' delay in milliseconds
TX_BYTE         SUB     1                       ' transmit a byte
TX_STR          SUB     2                       ' transmit a string
RESET_RC4       SUB     0                       ' reset the RC-4
SET_RC4         SUB     1                       ' set RC-4 relays


' -------------------------------------------------------------------------
' Program Code
' -------------------------------------------------------------------------

Start:
  PLP_A = %0000                                 ' pull-up unused pins
  PLP_B = %00000000
  PLP_C = %10000000

  DELAY_MS 250                                  ' let RC-4 power up
  RESET_RC4                                     ' reset it


Main:
  FOR relays = %0000 TO %1111
    SET_RC4 relays
    DELAY_MS 500
  NEXT

  DELAY_MS 500
  SET_RC4 %0111
  DELAY_MS 500
  SET_RC4 %0011
  DELAY_MS 500
  SET_RC4 %0001
  DELAY_MS 500
  SET_RC4 %0000

  DELAY_MS 2000
  GOTO Main


' -------------------------------------------------------------------------
' Subroutine / Function Code
' -------------------------------------------------------------------------

' Use: DELAY_MS milliseconds

SUB DELAY_MS
  IF __PARAMCNT = 1 THEN
    tmpW1 = __PARAM1
  ELSE
    tmpW1 = __WPARAM12
  ENDIF
  PAUSE tmpW1
  ENDSUB

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

' Use: TX_BYTE byteVal
' -- transmit "byteVal" at "BaudMode" on pin "Sio"

SUB TX_BYTE
  SEROUT Sio, BaudMode, __PARAM1
  ENDSUB

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

' Use: TX_STR [string | label]
' -- "string" is an embedded string constant
' -- "label" is DATA statement label for stored z-String

SUB TX_STR
  tmpW1 = __WPARAM12                            ' get address of string
  DO
    READINC tmpW1, tmpB1                        ' read a character
    IF tmpB1 = 0 THEN EXIT                      ' if 0, string complete
    TX_BYTE tmpB1                               ' send character
  LOOP
  ENDSUB

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

' Use: RESET_RC4

SUB RESET_RC4
  TX_STR  "!!!!!!RC4"                           ' header (ensure sync)
  TX_BYTE %00                                   ' address
  TX_BYTE "X"                                   ' reset command
  ENDSUB

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

' Use: SET_RC4 relayBits

SUB SET_RC4
  tmpB2 = __PARAM1                              ' get relay bits
  TX_STR  "!RC4"                                ' header
  TX_BYTE %00                                   ' address
  TX_BYTE "S"                                   ' set command
  TX_BYTE tmpB2                                 ' relay bits
  ENDSUB


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

tds234

Thanks Jon!
This is coming together rather nicely! RC-4 and AP-8 are working now and it's awesome.
Here's the code so far for those interested:
' =========================================================================
'
'   File...... TDS3.SXB
'   Purpose...
'   Author.... TDS -- updated by Jon Williams, EFX-TEK
'   E-mail....
'   Started...
'   Updated...
'
' =========================================================================


' -------------------------------------------------------------------------
' Program Description
' -------------------------------------------------------------------------


' -------------------------------------------------------------------------
' Conditional Compilation Symbols
' -------------------------------------------------------------------------


' -------------------------------------------------------------------------
' Device Settings
' -------------------------------------------------------------------------

'DEVICE          SX28, OSC4MHZ, TURBO, STACKX, OPTIONX, BOR42
'FREQ            4_000_000
DEVICE          SX28, OSCXT2, TURBO, STACKX, OPTIONX, BOR42
FREQ            20_000_000

ID              "TDS3"


' -------------------------------------------------------------------------
' I/O Pins
' -------------------------------------------------------------------------

AlarmLed        PIN     RB.0 OUTPUT
SensorLed       PIN     RB.5 OUTPUT
Trigger         PIN     RB.6 INPUT
Sio             PIN     RB.7                    ' no SETUP, no ULN

RedLight1       PIN     RC.0 OUTPUT
RedLight2       PIN     RC.1 OUTPUT
Motor1          PIN     RC.2 OUTPUT
Motor2          PIN     RC.6 OUTPUT
'Strobe          PIN     RC.3 OUTPUT
'Popper          PIN     RC.4 OUTPUT
'AmbientLights   PIN     RC.5 OUTPUT
'MusicTrigger    PIN     RC.7 OUTPUT


' -------------------------------------------------------------------------
' Constants
' -------------------------------------------------------------------------

BlinkDelay      CON     250                     ' blink rate
BlinkFast       CON     100
Timeout         CON     1000
Bumpstart       CON     50

IsOn            CON     1
IsOff           CON     0

BaudMode        CON     "OT38400"

' -------------------------------------------------------------------------
' Variables
' -------------------------------------------------------------------------

lottery         VAR     Byte                    ' random value
check           VAR     Byte
idx             VAR     Byte
bumper          VAR     Byte

tmpB1           VAR     Byte                    ' for subs/funcs
tmpB2           VAR     Byte
tmpW1           VAR     Word


' =========================================================================
  PROGRAM Start
' =========================================================================


' -------------------------------------------------------------------------
' Subroutine / Function Declarations
' -------------------------------------------------------------------------

DELAY_MS        SUB     1, 2                    ' delay in milliseconds
ALL_OFF         SUB     0
WAKE_UP         SUB     0
PLAY_MUSIC      SUB     0
RND_ACTIVITY    SUB     1
RX_BYTE         FUNC    1, 0                    ' receive a byte
TX_BYTE         SUB     1                       ' transmit a byte
TX_STR          SUB     2                       ' transmit a string

AmbientLightsOn SUB   0
AmbientLightsOff SUB   0
StrobeLightsOn SUB   0
StrobeLightsOff SUB   0
PopperOn    SUB   0
PopperOff    SUB   0
PlaySoundSeg    SUB   1

RESET_RC4       SUB     0                       ' reset the RC-4
SET_RC4         SUB     1                       ' set RC-4 relays
SET_RC4_ON      SUB     1                       ' set RC-4 relays
SET_RC4_OFF     SUB     1                       ' set RC-4 relays

' -------------------------------------------------------------------------
' Program Code
' -------------------------------------------------------------------------

Start:
  'MusicTrigger = IsOff
  AlarmLed = IsOff
  'Popper = IsOff
  SensorLed = IsOff
  PLP_B = %1000000
 

  DELAY_MS 1000
  RESET_RC4
  DELAY_MS 500
  SET_RC4 %0000

  'For idx = 0 to 7
   'PlaySoundSeg idx
   'DELAY_MS 6000
  'next

  ALL_OFF
  DELAY_MS 5000
  WAKE_UP

  'warm up sensor
  SensorLed = IsOn
  DELAY_MS 30_000
  SensorLed = IsOff

Setup:
  AmbientLightsOn

Main:
  DO WHILE Trigger = IsOff
    RANDOM lottery
    DELAY_MS BlinkDelay
    AlarmLed = ~AlarmLed                        ' toggle LED
    IF bumper = 0 THEN
      RND_ACTIVITY lottery
    ELSE
      DEC bumper
    ENDIF
  LOOP

  AlarmLed = IsOff
  RANDOM lottery                          ' seed it again

Act_1:
  'PLAY_MUSIC
  RedLight1 = IsOn
  RedLight2 = IsOn
  PlaySoundSeg 0
  DELAY_MS 11_000
  ALL_OFF

Act_2:
  FOR idx = 1 TO 65
    RedLight1 = ~RedLight1                      ' toggle
    RedLight2 = RedLight1                       ' follow #1
    check = idx // 5
    IF check = 0 THEN
      Motor1 = ~Motor1
    ENDIF
    DELAY_MS BlinkDelay
  NEXT
  ALL_OFF

Act_3:
  RedLight1 = IsOn
  Motor1 = IsOn
  ' Motor2 = IsOn
  FOR idx = 1 TO 75
    RedLight1 = ~RedLight1                      ' toggle
    RedLight2 = ~RedLight1                      ' opposite of #1
    DELAY_MS BlinkFast
  NEXT
  All_OFF   

Act_4:                                          ' the payoff
  AmbientLightsOff
  DELAY_MS 250
  StrobeLightsOn
  DELAY_MS 2000

  PopperOn
  DELAY_MS 2000
  PopperOff
  DELAY_MS 1000
  StrobeLightsOff
  ALL_OFF

Reset_Show:
  DELAY_MS 3000
  AlarmLed = IsOn
  AmbientLightsOn
  DELAY_MS 10_000
  bumper = BumpStart

  GOTO Main


' -------------------------------------------------------------------------
' Subroutine / Function Code
' -------------------------------------------------------------------------

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

' Use: byteVal = RX_BYTE
' -- receive "byteVal" at "BaudMode" on pin "Sio"

FUNC RX_BYTE
  SERIN Sio, BaudMode, tmpB1
  RETURN tmpB1
  ENDFUNC

' -------------------------------------------------------------------------
SUB AmbientLightsOn
   SET_RC4_ON 3
ENDSUB

SUB AmbientLightsOff
   SET_RC4_OFF 3
ENDSUB

SUB StrobeLightsOn
   SET_RC4_ON 1
ENDSUB

SUB StrobeLightsOff
   SET_RC4_OFF 1
ENDSUB

SUB PopperOn
   SET_RC4_ON 4
ENDSUB

SUB PopperOff
   SET_RC4_OFF 4
ENDSUB

SUB PlaySoundSeg
  TX_STR  "!AP8"                                ' header
  TX_BYTE %11                                   ' address
  TX_BYTE "X"                                   ' set command
  'TX_BYTE tmpB2                                 ' relay bits
  DELAY_MS 200

  tmpB2 = __PARAM1                              ' get relay bits
  TX_STR  "!AP8"                                ' header
  TX_BYTE %11                                   ' address
  TX_BYTE "P"                                   ' set command
  TX_BYTE tmpB2                                 ' relay bits
ENDSUB

SUB SET_RC4
  tmpB2 = __PARAM1                              ' get relay bits
  TX_STR  "!RC4"                                ' header
  TX_BYTE %11                                   ' address
  TX_BYTE "S"                                   ' set command
  TX_BYTE tmpB2                                 ' relay bits
  ENDSUB

SUB SET_RC4_ON
  tmpB2 = __PARAM1                              ' get relay bits
  TX_STR  "!RC4"                                ' header
  TX_BYTE %11                                   ' address
  TX_BYTE "R"                                   ' set command
  TX_BYTE tmpB2                                 ' relay #
  TX_BYTE 1
  ENDSUB

SUB SET_RC4_OFF
  tmpB2 = __PARAM1                              ' get relay bits
  TX_STR  "!RC4"                                ' header
  TX_BYTE %11                                   ' address
  TX_BYTE "R"                                   ' set command
  TX_BYTE tmpB2                                 ' relay #
  TX_BYTE 0
  ENDSUB

SUB RESET_RC4
  TX_STR  "!!!!!!RC4"                           ' header (ensure sync)
  TX_BYTE %11                                   ' address
  TX_BYTE "X"                                   ' reset command
  ENDSUB

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

' Use: TX_BYTE byteVal
' -- transmit "byteVal" at "BaudMode" on pin "Sio"

SUB TX_BYTE
  SEROUT Sio, BaudMode, __PARAM1
ENDSUB

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

' Use: TX_STR [string | label]
' -- "string" is an embedded string constant
' -- "label" is DATA statement label for stored z-String

SUB TX_STR
  tmpW1 = __WPARAM12                            ' get address of string
  DO
    READINC tmpW1, tmpB1                        ' read a character
    IF tmpB1 = 0 THEN EXIT                      ' if 0, string complete
    TX_BYTE tmpB1                               ' send character
  LOOP
  ENDSUB

' Use: DELAY_MS milliseconds

SUB DELAY_MS
  IF __PARAMCNT = 1 THEN
    tmpW1 = __PARAM1
  ELSE
    tmpW1 = __WPARAM12
  ENDIF
  PAUSE tmpW1
  ENDSUB

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

SUB ALL_OFF
  RedLight1 = IsOff
  RedLight2 = IsOff
  Motor1 = IsOff
  Motor2 = IsOff
  'Strobe = IsOff
  'Popper = IsOff
  'AmbientLights = IsOff
  ENDSUB

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

SUB WAKE_UP

  PlaySoundSeg 0

  Motor1 = IsOn
  DELAY_MS 4000
  Motor1 = IsOff
 
  DELAY_MS 2000

  Motor2 = IsOn
  DELAY_MS 4000
  Motor2 = IsOff
 
  DELAY_MS 2000

  Redlight1 = IsOn
  DELAY_MS 4000
  Redlight1 = IsOff
 
  DELAY_MS 2000

  Redlight2 = IsOn
  DELAY_MS 4000
  Redlight2 = IsOff
  DELAY_MS 2000

  AmbientLightsOn
  DELAY_MS 2000
  AmbientLightsOff
  DELAY_MS 2000

  StrobeLightsOn
  DELAY_MS 2000
  StrobeLightsOff
  DELAY_MS 2000

  'PLAY_MUSIC

  ENDSUB

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

SUB PLAY_MUSIC
  'MusicTrigger = IsOn
  'DELAY_MS 50
  'MusicTrigger = IsOff
  ENDSUB

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

' Use: RND_ACTIVITY seed
' -- seed should be randomized before calling

SUB RND_ACTIVITY
  tmpB1 = __PARAM1
  tmpB2 = tmpB1 // 100

  IF tmpB2 = 0 THEN
     SensorLed = IsOn
     DELAY_MS 250
     SensorLed = IsOff

    tmpB2 = tmpB1 // 5

    IF tmpB2 = 0 THEN
      Motor1 = IsOn
      DELAY_MS 2000
      Motor1 = IsOff
    ENDIF

    IF tmpB2 = 1 THEN
      Motor2 = IsOn
      DELAY_MS 2000
      Motor2 = IsOff
    ENDIF

    IF tmpB2 = 2 THEN
      RedLight1 = IsOn
      DELAY_MS 2000
      RedLight1 = IsOff
    ENDIF

    IF tmpB2 = 3 THEN
      RedLight2 = IsOn
      DELAY_MS 2000
      RedLight2 = IsOff
    ENDIF

    IF tmpB2 = 4 THEN
      StrobeLightsOn
      DELAY_MS 2000
      StrobeLightsOff
    ENDIF

    bumper = BumpStart                          ' reset timer
  ENDIF
  ENDSUB


' -------------------------------------------------------------------------
' User Data
' -------------------------------------------------------------------------

JonnyMac

You don't have to pre-pend the "X" command to the AP-8's "P" command -- that happens internally.
Jon McPhalen
EFX-TEK Hollywood Office

tds234

Ok, maybe for advanced builders this is just 'Meh' but here's the current version of my haunt show controller set up.
In this box, the Prop-SX ( it ROCKS) and and AP-8 and in a separate box (not pictured) an RC-8 ...

JonnyMac

Right on!  Plastic show boxes and similar containers are great for mounting and protecting our boards when you're going to put them outside.
Jon McPhalen
EFX-TEK Hollywood Office

livinlowe

Tds (or Jon, or anyone who can help clear this up!)-
In yuou final code you have two device lines which are the same except for the frequency callout. Which will the SX use? Do you need both?
Can you run a 20 Mhz crystal and only have the program at 4 Mhz, or must it run at the resonator frequency? I don't have a Prop-SX(yet), but I do have the SX tech board, so I am trying to gain some knowledge.

Thanks
Shawn
Shawn
Scaring someone with a prop you built -- priceless!

JonnyMac

November 27, 2007, 10:07:57 AM #7 Last Edit: November 27, 2007, 10:10:31 AM by JonnyMac
I looks like he has one set of lines commented out.  That said, let me explain a bit about the DEVICE line.

Let's say you had a simple control project that didn't use serial communications (which are very timing sensitive).  This set of fuse configuration lines will work just fine:

DEVICE          SX28, OSC4MHZ, TURBO, STACKX, OPTIONX, BOR42
FREQ            4_000_000


This is telling the SX to run a 4 MHz (FREQ directive) and use the internal 4 MHz oscillator (OSC4MHZ).  The frequency of the internal oscillator can vary by about 8% so it's not stable enough to use for SERIN and SEROUT.  If you want to add serial comms to the project you would simply plug in a 4 MHz resonator and change the configuration:

DEVICE          SX28, OSCXT2, TURBO, STACKX, OPTIONX, BOR42
FREQ            4_000_000


Note the change in the DEVICE line, we've switched to OSCXT2 to use an external source and drive the resonator appropriately.  If you need better resolution or more speed in the program (internally, that is), then use a 20 or 50 MHz resonator and make the change to the FREQ directive.
Jon McPhalen
EFX-TEK Hollywood Office

livinlowe

Whoops!  ;D Yeah, I missed that he commented out those lines. So, I understand about changing the device line, and the freq line appropriately I was just unsure about having to run at the resonator frequency. Thanks for that clarification/education!!!

Shawn
Shawn
Scaring someone with a prop you built -- priceless!