Shop OBEX P1 Docs P2 Docs Learn Events
RCtime command and the bar graph — Parallax Forums

RCtime command and the bar graph

youngbillyoungbill Posts: 54
edited 2010-11-04 14:20 in BASIC Stamp
I have built the bar graph in stamp works Ex #5,,ver 2.1
Does anyone know if there are other stamp works ( or nuts and bolts) available? Here was the code,,In the text it explains to scale we divide by 695/255. where does this 695 number come from?
Any suggestions where to learn more on scale, etc, to know how this code works.
What I want is a more lively display,,,I have a photo resistor of 1k bright light to 10k when dark,,,,,,could this replace the pot directly?
Or would it be possible to use random numbers ,to generate a moving display.

Program: SW21-EX05-LED_Graph.BS2:
' {$STAMP BS2}
' {$PBASIC 2.5}
'
[ Program Description ]
'
' Displays a linear (bar) or dot graph using eight LEDs. This program
' will require modifications (to the constants LoScale and HiScale) when
' running on the BS2Sx, BS2p, or BS2px.
'
[ I/O Definitions ]
LEDs VAR OUTL ' LEDs on P0 - P7
LEDsDirs VAR DIRL ' DIRS control for LEDs
Pot PIN 15 ' Pot circuit IO
'
[ Constants ]
DotGraf CON 0 ' define graph types
BarGraf CON 1
GraphMode CON BarGraf ' define graph mode
IsOn CON 1
IsOff CON 0
LoScale CON 10 ' raw low reading
HiScale CON 695 ' raw high reading
Span CON HiScale - LoScale ' between lo-to-hi
Scale CON $FFFF / Span ' scale factor 0..255
'
[ Variables ]
rawVal VAR Word ' raw value from pot
grafVal VAR Byte ' graph value
hiBit VAR Byte ' highest lighted bit
newBar VAR Byte ' workspace for bar graph
Page 42 · StampWorks
'
[ Initialization ]
Reset:
LEDsDirs = %11111111 ' make LEDs outputs
'
[ Program Code ]
Main:
DO
GOSUB Read_Pot ' get raw pot value
grafVal = (rawVal - LoScale) */ Scale ' z-adjust, then scale
GOSUB Show_Graph ' now show it
PAUSE 50
LOOP
'
[ Subroutines ]
Read_Pot:
HIGH Pot ' charge cap
PAUSE 1 ' for 1 millisecond
RCTIME Pot, 1, rawVal ' read the Pot
RETURN
Show_Graph:
hiBit = DCD (grafVal / 32) ' get highest bit
IF (GraphMode = BarGraf) THEN
newBar = 0 ' clear bar workspace
IF (grafVal > 0) THEN
DO WHILE (hiBit > 0) ' all bar LEDs lit?
newBar = newBar << 1 ' no - shift left
newBar.BIT0 = IsOn ' light low end
hiBit = hiBit >> 1 ' mark bit lit
LOOP
ENDIF
LEDs = newBar ' output new level
ELSE
LEDs = hiBit ' show dot value
ENDIF
RETURN

Comments

  • $WMc%$WMc% Posts: 1,884
    edited 2010-11-03 17:24
    yougbill:
    '
    Take a look at experiment #26 in StampWorks.
    '
    This explanes the timeing and scale a little better.
    '
    note a small miss print in the math, the 250 should be 500.
    '
    Raw RCTIME value: 645
    500/645 = 0.775
    0.775 X 256 = 198(This is the value called Scale.
    '
    Hope this helps!
  • ercoerco Posts: 20,256
    edited 2010-11-04 14:20
    Youngbill:

    Since you're having fun with bargraphs, you may want to see my post about the LM3914 bargraph chip in the thread at http://forums.parallax.com/showthread.php?t=126533

    That chip is cheaper than a Stamp, so if you only need simple bargraph, you might be able to use an LM3914 and save your Stamp for something else.
Sign In or Register to comment.