home  >  Tiny Tim  >  Tiny-Tim Program 29 September 2005

' {$STAMP BS1}
'>TinyTim                                      DLB 20-5-94
READ 255,B0 :DEBUG B0   'b0=4    =first byte used, ie. 2 => 0 and 1 free
'14-4-97 tidyed, keywords now in uppercase
'9-4-97  Tiny Tim's Hg cells (4.05v) changed to Ag cells (4.5v)
'29-7-96 bump L was 42 now 40, Song2 was for 3 now 2
'0-Rmf  1-Rmb  2-Lmf  3-Lmb  4-whiskers 5-speaker  6-eyeR  7-eyeL
'm-motor  f-forward  b-backward  R-right  L-left
'bump sensors -:  Rf-4k7 Lf-10k Rr-22k Lr-47k, all in parallel then in series with 0u1
'eyes:- each side - LDR in series with 0u1
'f-front  r-rear

'random reversing time 'revtime' in Song3 avoids repeated bump/reverse

'w0                  b1 FOR counter i     b0 temp for prog size
'w1                  b3 POT darkL         b2 POT bump, darkR
'w2                  b5 dark gradient     b4
'w3                  b7                   b6 movemask
'w4                  b9 explore counter   b8 frustrated counter
'w5 RANDOM freewill  b11 revtime          b10 randmove
SYMBOL whiskers   =4     'Pin4
SYMBOL spkr       =5     'Pin5   speaker
SYMBOL eyeR       =6     'Pin6   right LDR
SYMBOL eyeL       =7     'Pin7   left LDR
SYMBOL i          =B1    'FOR counter
SYMBOL bump       =B2
SYMBOL darkR      =B2    'right eye light level
SYMBOL darkL      =B3    'left eye light level
SYMBOL deltadark  =B5    'darkness gradient between left and right eyes
SYMBOL movemask   =B6    '%1010=>motors forward only
SYMBOL frust      =B8    'frustrated level
SYMBOL explores   =B9    'explore counter
SYMBOL randmove   =B10   'random value for motor pins gives random move
SYMBOL revtime    =B11   'reverse time in Song3 for avoid
SYMBOL freewill   =W5    'RANDOM
SYMBOL bumpscale  =55    'adjust so b2 unbumped is 33, b2 prop to scale
SYMBOL wfront     =150   'threshold for both front whiskers hit
SYMBOL wright     =70    'threshold for right front whisker hit
SYMBOL wleft      =40    'threshold for left front whisker hit
' can't reliably tell which rear whisker is hit so don't try
SYMBOL nobump     =34    'threshold for bumping
SYMBOL lightscale =100
SYMBOL bright     =50    'black is 255, incandescent is 0
SYMBOL evendark   =20    'minimum difference between eyes for action
SYMBOL exploremax =6     'explore loops+1 before new move
SYMBOL frustrated =50    '<maxfrust
SYMBOL maxfrust   =60    '<254 otherwise counts to 0!!
SYMBOL frustup    =5     'frustration growth rate
SYMBOL frustdown  =1     'frustration decay rate

  frust =0
  movemask =%1010     'only forwards

  DIRS =%1111    ' motor pins to Output in case noise corrupted them
  GOSUB Song     'timer for main loop
  RANDOM freewill
  revtime =revtime&%11    'limit to random time in Song3 for avoids
  frust =frust -frustdown
  frust =frust MIN 1
'debug %pins
  POT whiskers,bumpscale,bump
DEBUG bump
  IF bump<nobump THEN eyes           'ie no bump   'else
    frust =frust +frustup            'bumped so increment
    movemask =%1010                  'guess motors only forward
    IF frust<frustrated THEN cont1   'else really frustrated so
      movemask =%1111                'motors any direction
      frust =frust MAX maxfrust      'endif, endif
    IF bump>wfront THEN avoidLR      'bumped both front whiskers
    IF bump>wright THEN avoidR       'bumped front right whisker
    IF bump>wleft THEN avoidL        'bumped front left whisker
    movemask =%1010
    GOTO newmove                     'must be at rear so avoid rear

  POT eyeR,lightscale,darkR
  POT eyeL,lightscale,darkL
DEBUG #darkL,#darkR,CR               'cmnd only takes 2 bytes!
  IF darkR>darkL THEN darkright

  deltadark =darkL -darkR
  IF deltadark<evendark THEN explore 'even light so explore
  IF darkR>bright THEN turnright     'if bright light then rotate
  GOTO curveright                    'else curve towards light

  deltadark =darkR -darkL
  IF deltadark<evendark THEN explore 'even light so explore
  IF darkL>bright THEN turnleft      'if bright light then rotate
  GOTO curveleft                     'else curve towards light

  explores =explores +1
  IF explores<exploremax THEN start  'else newmove

  PINS =randmove&movemask            'new motor settings
  explores =0                        'reset counter
  GOTO start

  PINS =%0101 :GOSUB Song3 :PINS =%0100 :NAP 4 :GOTO start
  PINS =%0101 :GOSUB Song3 :PINS =%0100 :NAP 4 :GOTO start
  PINS =%0101 :GOSUB Song3 :PINS =%0001 :NAP 4 :GOTO start
  PINS =%0110 :GOSUB Song2 :GOTO start
  PINS =%1001 :GOSUB Song2 :GOTO start
  PINS =%0010 :GOSUB Song1 :GOTO start
  PINS =%1000 :GOSUB Song1 :GOTO start

  FOR i =100 TO 110
    SOUND spkr,(i,1)
   NEXT i
  SOUND spkr,(100,5,0,5)
  SOUND spkr,(126,2,0,2)
  FOR i =0 TO 50
    SOUND spkr,(227,revtime)
   NEXT i

'Song5:     SOUND spkr,(227,10) :RETURN
'Song4:     SOUND spkr,(180,revtime) :RETURN

home  >  Tiny Tim  ,  top