Shop OBEX P1 Docs P2 Docs Learn Events
Need help with Lookdown and lookup tables — Parallax Forums

Need help with Lookdown and lookup tables

IroneIrone Posts: 116
edited 2013-03-26 06:12 in BASIC Stamp
Hello,
I am making a tachometer for my 87 Wheel Horse garden tractor using a hall sensor and seven button magnets. I have already made a code that counts seven magnets glued to the vanes of a cooling fan for a computer I found in my junk box that works. My next step is to send the outputs to four seven segment LED's. Having a few of these seven segment LED's in my junk box I am going to try to light them sequentially and rely on persistence of vision to have them look reasonable. Can you use outl as a variable for the end of a lookup table? Here's my code.
' {$STAMP BS2}
' {$PBASIC 2.5}

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

RPM   PIN   8

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

RPM = 6543

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

fst   VAR     Nib
snd   VAR     Nib
trd   VAR     Nib
fth   VAR     Nib
index VAR     Nib

'-----[ Initializations ]-------------------------------------------


  OUTL = %00000000
  DIRL = %11111111

  DO

  fst = RPM DIG 3
  snd = RPM DIG 2
  trd = RPM DIG 1
  fth = RPM DIG 0

    LOOKDOWN fst, [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], index
    LOOKUP index, [ "%11100111", "%10000100", "%11010011", "%11010110", "%10110100",
                    "%01110110", "%01110111", "%11000100", "%11110111", "%11110110" ], OUTL

    PAUSE 500
    DEBUG BIN8 OUTL, CR
    PAUSE 500

    LOOKDOWN snd, [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], index
    LOOKUP index, [ "%11100111", "%10000100", "%11010011", "%11010110", "%10110100",
                    "%01110110", "%01110111", "%11000100", "%11110111", "%11110110" ], OUTL

    PAUSE 500
    DEBUG BIN8 OUTL, CR
    PAUSE 500

    LOOKDOWN trd, [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], index
    LOOKUP index, [ "%11100111", "%10000100", "%11010011", "%11010110", "%10110100",
                    "%01110110", "%01110111", "%11000100", "%11110111", "%11110110" ], OUTL

    PAUSE 500
    DEBUG BIN8 OUTL, CR
    PAUSE 500

    LOOKDOWN fth, [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], index
    LOOKUP index, [ "%11100111", "%10000100", "%11010011", "%11010110", "%10110100",
                    "%01110110", "%01110111", "%11000100", "%11110111", "%11110110" ], OUTL

    PAUSE 500
    DEBUG BIN8 OUTL, CR
    PAUSE 500


LOOP

Right now I am just checking what is in the OUTL, it should be 6543 in separate binary numbers but it is not.

Comments

  • SapphireSapphire Posts: 496
    edited 2013-03-24 21:02
    Yes, you can use OUTL as the result of a LOOKUP statement.

    Also, you do not need to use the LOOKDOWN statement at all. The DIG operator give you the index you want for your LOOKUP statement. You can simiplify you code by putting it in a loop:
    FOR x = 0 TO 3
      LOOKUP rpm DIG x,[ %100111, %000100, %010011, %010110, %110100,
                         %110110, %110111, %000100, %110111, %110110 ], OUTL
    NEXT
    

    Notice that you do not need quotes in the LOOKUP list. And before the NEXT is where you would strobe each digit as you go through the loop.
  • IroneIrone Posts: 116
    edited 2013-03-25 14:47
    Hello,

    Thank you very much Sapphire! I stumbled on the DIG directive in the help section of the Basic Stamp Editor about a week or so ago and saw you could use a FOR, NEXT command but my mind could not see any way of using it. Your code is compact and neat. About those parentheses, somehow I remembered seeing them on the Christmas Carols program for DATA and worked them into my LOOKUP and LOOKDOWN tables. Oh well, on to the next section, trying to set up four seven segment LED's in parallel. ( I know if I need help that this is the place to go.)
  • PropNut1960PropNut1960 Posts: 23
    edited 2013-03-25 16:48
    I never doubt anyone for being ambitious, but there are products out there for small engines, they work great and they're pretty cheap. Here's one:
    http://www.ebay.com/itm/Tachometer-Hour-meter-2-4-Stroke-Small-Engine-Spark-utv-atv-outboard-motor-pwc-/400368946443?pt=Motorcycles_Parts_Accessories&hash=item5d37d94d0b&vxp=mtr
  • IroneIrone Posts: 116
    edited 2013-03-26 06:12
    Hello,

    Ambitious I am not but I need more practice setting programs for the BS2. I set one 7 segment LED on the breadboard but it has a common anode. I then inverted the ones and zeros for the bafg.cde. That gave me weird readings till I set it up as edc.gfab. Anyhow this winter has not been cold enough for the ice to freeze to hold up my weight, nor warm enough to put the boat in the water so I must keep busy.
Sign In or Register to comment.