Shop OBEX P1 Docs P2 Docs Learn Events
Code not working...? — Parallax Forums

Code not working...?

NoBo780NoBo780 Posts: 94
edited 2007-11-01 00:58 in BASIC Stamp
I am writing code for my interactive robot, but for some reason, after I edited something, it suddenly stopped working. All that happens is the emic tts module just resets, and then it doesn't execute the startup sound. What's wrong??
confused Here's the code:
' {$STAMP BS2e}
' {$PBASIC 2.5}

' ***Credits***  --> R2D2 sounds: cpuman3@hotmail.com

cdstime           VAR   Word                     ' Photocell RCTIME
pulsecount        VAR   Word                     ' pulse counter for servos
counter           VAR   Word
i                 VAR   Word                     ' for sound generation
j                 VAR   Word                     ' for sound generation
frontirstate      VAR   Byte                     ' state of front IR
backirstate       VAR   Byte                     ' state of rear IR
vol               VAR   Nib                     ' current volume
spd               VAR   Nib                     ' current speed
ptch              VAR   Nib                     ' current pitch
spkr              VAR   Nib                     ' for sound generation
frontir           CON   10                      ' IR port
backir            CON   9                       ' IR port

' -----[noparse][[/noparse] Emic Commands (Hex Mode) ] --------------------------------------------------------------------------------------

Say             CON     $00                     ' say Engish text
Volume          CON     $01                     ' set volume, 0 - 7
Speed           CON     $02                     ' set speed, 0 - 4
Pitch           CON     $03                     ' set pitch, 0 - 6
AddAbbr         CON     $04                     ' add abbreviation
DelAbbr         CON     $05                     ' delete abbreviation
ListAbbr        CON     $06                     ' list abbreviations
Version         CON     $07                     ' get version
Reset           CON     $08                     ' soft reset
Audio           CON     $09                     ' enable audio in
PhT             CON     $10                     ' start of phonetic text
Help            CON     $FE                     ' display help
EOM             CON     $AA                     ' end of message

OK              CON     $55                     ' "okay" for hex mode

' -----[noparse][[/noparse] Emic Communication ]---------------------------------------------------------------------------------------------

Baud            CON     396                     ' 2400 baud, N81

Yes             CON     1
No              CON     0

Tx              PIN     1                       ' connects to Emic SIn
Rx              PIN     2                       ' connects to Emic SOut
Busy            PIN     3                       ' 1 = busy
Rst             PIN     4                       ' low to reset Emic TTS

' -----[noparse][[/noparse] Initialization ]-------------------------------------------------------------------------------------------------

spkr = 8                                        ' AOUT pin (audio out) to the emic
OUTPUT spkr
PAUSE 200
GOSUB Startup_Sound

' -----[noparse][[/noparse] Main Program ]---------------------------------------------------------------------------------------------------

Main:

DO

INPUT   frontir
INPUT   backir

HIGH 0
PAUSE 100
RCTIME 0, 1, cdstime
DEBUG HOME, "cdstime = ", DEC5 cdstime

 frontirstate = IN10
 backirstate = IN9
  'IF frontirstate = 1  AND backirstate = 0 THEN          ' if fron IR detects the floor, and rear IR sees nothing, then
    'GOSUB Roam_Around                                    ' roam around
  'ENDIF

  IF (frontirstate = 1) AND (backirstate = 1) THEN        ' if on the ground, and rear IR detects presence, then
    counter = counter + 1                                 ' add 1 to the counter
  ENDIF

  IF (counter <= 5) AND (counter > 0) THEN                ' if it moved by quickly (it's a person not an object), then
    counter = 0                                           ' reset counter to zero
    FOR pulsecount = 0 TO 220                             ' turn around
    PULSOUT 13, 820
    PULSOUT 12, 850
    NEXT
  ENDIF




LOOP



Check_Busy:
  PAUSE 1                                       ' allow busy to activate
  DO WHILE (Busy = Yes) : LOOP                  ' wait until not busy
  RETURN

Roam_Around:

Soft_Reset:
  GOSUB Check_Busy                              ' wait for busy to release
  SEROUT Tx, Baud, [noparse][[/noparse]Reset, EOM]                 ' send soft reset
  GOSUB Wait_OK
  vol = 7                                       ' set pgm vars to defaults
  spd = 2
  ptch = 1
  RETURN

Hard_Reset:                                     ' reset to default values
  LOW Rst                                       ' pull reset line low
  PAUSE 0                                       ' ~100 uS pause
  INPUT Rst                                     ' let reset float
  GOSUB Wait_OK
  vol = 4                                       ' set pgm vars to defaults
  spd = 2
  ptch = 1
  RETURN

Wait_OK:
  SERIN Rx, Baud, 1000, TO_Error, [noparse][[/noparse]WAIT(OK)]
  RETURN

TO_Error:
  DEBUG CLS, "No response from Emic TTS."       ' ruh-roh, Shaggy
  END
  vol = 7                                       ' set pgm vars to defaults
  spd = 2
  ptch = 1
  RETURN

' -----[noparse][[/noparse] R2D2 Sounds ]----------------------------------------------------------------------------------------------------

sound_0:
   FOR j = 1 TO 4
      FOR i=2000 TO 50 STEP 400
         FREQOUT spkr,10,i
      NEXT
      FOR i=800 TO 2000 STEP 400
         FREQOUT spkr,10,i
      NEXT
   NEXT
RETURN

sound_1:
   FOR i = 800 TO 2000 STEP 100
      FREQOUT spkr,10,i
   NEXT
   FOR i= 2000 TO 50 STEP 100
      FREQOUT spkr,10,i
   NEXT
RETURN

sound_2:
   FOR i = 1000 TO 40 STEP 20
      FREQOUT spkr,10,i
   NEXT
RETURN

sound_3:
   FOR i = 10000 TO 500 STEP 500
      FREQOUT spkr,10,i
   NEXT
RETURN

sound_4:
   FOR i = 10 TO 50 STEP 10
      FOR j = 50 TO 10 STEP 10
         FREQOUT spkr,15,j*20
      NEXT
   NEXT
RETURN

sound_5:
   FOR i = 1 TO 120 STEP 2
      FREQOUT spkr,10,(SIN(i + 40) * 50)
   NEXT
RETURN

sound_6:
   FOR i = 10 TO 50 STEP 10
      FOR j = 50 TO 10 STEP 10
         FREQOUT spkr,10,i * J
      NEXT
   NEXT
RETURN

sound_7:
   FOR i = 30 TO 70 STEP 5
      FOR j = 70 TO 30 STEP 5
         FREQOUT spkr,10,i*j
      NEXT
   NEXT
RETURN

sound_8:
   FOR i= 30 TO 60 STEP 10
      FOR j = 60 TO 30 STEP 10
         FREQOUT spkr,10,i * j
      NEXT
   NEXT
RETURN


sound_9:
   FOR i = 1 TO 60 STEP 7
      FREQOUT spkr,10,(SIN(i) + 20) * 30
   NEXT
RETURN

sound_10:
   FOR i = 1 TO 30
      FREQOUT spkr,20,(i * 14) + 450
   NEXT
RETURN

sound_11:
   FOR i = 10000 TO 500 STEP 500
      FREQOUT spkr,20,i
   NEXT
RETURN

sound_12:
   FOR i = 102 TO 82 STEP 2
      FREQOUT spkr,40,(COS(i/100) + 36) * 25
      FREQOUT spkr,20,(SIN(i/100) + 20) * 50
   NEXT
RETURN

sound_13:
   FOR i = 1 TO 10
      FREQOUT spkr,40,1195
      FREQOUT spkr,40,2571
   NEXT
RETURN

sound_14:
    FOR i= 1 TO 3
      FREQOUT spkr,90, 550
      FREQOUT spkr,90, 400
    NEXT
RETURN

sound_15:
   FOR i = 40 TO 15 STEP 1
      FREQOUT spkr,5,I * 90
      FREQOUT spkr,5,I * 80
      FREQOUT spkr,5,I * 70
      FREQOUT spkr,5,I * 60
      FREQOUT spkr,5,I * 50
   NEXT
RETURN

sound_16:
   FOR i = 1 TO 20
      FREQOUT spkr,20,1195 - 50 * I
      FREQOUT spkr,20,1195 + 50 * I
   NEXT
RETURN

sound_17:
   FOR i = 0 TO 150 STEP 10
      FREQOUT spkr,20,1295 - I
      FREQOUT spkr,20,1095 + I
   NEXT
RETURN

sound_18:
   FOR i = 1 TO 20
      FREQOUT spkr,10,I * 50
      FREQOUT spkr,10,I * 100
      FREQOUT spkr,10,I * 150
   NEXT
RETURN

Startup_Sound:
   GOSUB Check_Busy
    SEROUT Tx, Baud, [noparse][[/noparse]Audio, EOM]                             ' enable audio input to the emic
   FOR i = 1 TO 20
      FREQOUT spkr,10,I * 50
      FREQOUT spkr,10,I * 100
      FREQOUT spkr,10,I * 150
   NEXT
   FOR i = 800 TO 2000 STEP 100
      FREQOUT spkr,10,i
   NEXT
   FOR i= 2000 TO 50 STEP 100
      FREQOUT spkr,10,i
   NEXT
   FOR i = 1 TO 20
      FREQOUT spkr,10,I * 50
      FREQOUT spkr,10,I * 100
      FREQOUT spkr,10,I * 150
   NEXT
   GOSUB Hard_Reset                                           ' reset the emic so its ready for more commands
   GOTO Main                                                  ' return to main





confused.gif

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Giggly Googley!

Comments

  • allanlane5allanlane5 Posts: 3,815
    edited 2007-11-01 00:58
    It looks like you commented out your only call to "GOSUB RoamAround" -- so there's no 'sound' code to be executed.

    It also looks like the "RoamAround" code has been removed.
Sign In or Register to comment.