Basic Stamp II code:

 

' TWS-434 / RWS-434 testing

 

'-----Declarations-----

 

  loop_count      var  word               ' For...Next loop counter

  pulse_count     var  word               ' Used to set number of pulses delivered

 

'-----Initialization-----

 

  low 2                                   ' Light LED on pin2

  low 11                                  ' Light LED on pin11

  low 12                                  ' Set P12 right servo output-low

  low 13                                  ' Set P13 left  servo output-low

  pulse_count = 5                         ' Initial movement

 

'-----Main Routine-----

 

main:                                     ' Main routine

 

  high 2                                  ' Light LED on pin2

  high 11                                 ' Light LED on pin11

  pause 2000                              ' Allow for visual recognition

 

  serout 1,16780,["A"]                    ' Output pin1,8-bit:no-parity:inverted

 

  debug "transmit ok",cr                  ' Let user know if transmission successful

  low 11                                  ' Light LED if transmit ok

  pause 2000                              ' Pause program 2 seconds to see lights

 

  serin 0,16780,1000,timeout,[WAIT("A")]  ' Input pin0,8-bit:no-parity:inverted,1 second timeout

 

  debug "receive ok",cr                   ' Reception successful

  low 2                                   ' Light LED if transmit ok

  'gosub pulses                           ' Call "pulses" subroutine

  pause 2000                              ' Pause for 2 seconds

  goto main                               ' Return to beginning of program

 

  timeout:                                ' Did not receive in time

    debug "receive timed out",cr          ' Let user know of no reception

    high 2                                ' Turn off LED on pin2

    pause 2000                            ' Pause 2 seconds

  goto main                               ' Move again

 

'end main                                 ' End main routine

 

'-----Subroutines-----

 

  pulses:                                 ' "pulses" subroutine

    for loop_count = 1 to pulse_count     ' Determines distance to travel

      pulsout 12, 655                     ' Right servo

      pulsout 13, 850                     ' Left servo

      pause 20                            ' Wait 20 ms

    next

  return