Need help with Lookdown and lookup tables
Irone
Posts: 116
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.
Right now I am just checking what is in the OUTL, it should be 6543 in separate binary numbers but it is not.
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
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:
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.
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.)
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
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.