pot to display to relay
spuddudit
Posts: 10
i want to use the basic stamp to do time lapse photography, idea is to use a potentiometer to adjust time delay and display it on two multiplexed 7 segment displays. i can get it to show the same number on both displays but cant get it to show say: 10 or 12. i had a working prototype, but it used 3 switches and a serious IF-then program to set and display preset delays. any one got ideas, i have been working through the stamp works book but it doesn't combine a display %10101010 code with IF-THEN codes
Comments
' {$STAMP BS2}
' {$PBASIC 2.5}
index VAR Nib
time VAR Word
OUTH = %00000000
DIRH = %11111111
DO
HIGH 0
HIGH 5
PAUSE 100
RCTIME 5, 1, time
LOOKDOWN time, <= [noparse][[/noparse]50, 100, 150, 200, 250, 300, 350, 400, 450, 500, 550, 600,
650, 700, 750, 800 ], index
LOOKUP index, [noparse][[/noparse] %01110111, %00101001, %00100011, %01000111, %10000011,
%10000001, %00110111, %00000001, %00000111 ], OUTH
loop
my LED displays are backwards to i think because i had to do some experimenting to get the binary correct for digits 1 - 9
%01110111 = 1
%00101001 = 2
%00100011 = 3
%01000111 = 4
%10000011 = 5
%10000001 = 6
%00110111 = 7
%00000001 = 8
%00000111 = 9
also the LEDs are actually going to power two low voltage relay drivers, that tie into the stamp's VSS and VDD but if i can get the relays to flash correctly; ex
high 2
pause 400 ' focus relay
high 3
pause 250 ' close shutter
low 2
low 3
hope thats more info......
thanks
Spuddudit
Take your variable and divide it by 10, the remainder will go in another variable. You'll then send the quotient to the tens display and the remainder to the ones display. It will go something like this:
counter = pot value (Word sized variable)
tens VAR Word
ones VAR Word
tens = counter / 10 ' divide the pot value by ten, put the result in the tens variabe
ones = counter // 10 ' divide the pot value by ten, put the remainder in the ones variable
out xxxx, tens ' send the tens to the tens display
out xxxx, ones ' send the ones to the ones display
SO, if your pot reads 10
tens = 10 / 10 or 1
ones = 10 // 10 or 0
if your pot is 99
tens = 99 / 10 or 9
ones = 99 // 10 or 9
I hope it helps!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"puff"...... Smile, there went another one.
"also how do i tell it when 60 is displayed to pause 6000 between LED flashes?"
that would be done by scaling the result in "time". I'd start by setting the pot at some point and use a stop watch once it's all running...... Then adjust your scale (multiply or divide) to make the pot equal the time scale you want. Either that or adjust your R and C values.....
I can't help you with sending the "tens" and "ones" values to the display. You are using commands I'm not familiar with. But since you've got numbers currently displaying, it shouldn't be too hard.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"puff"...... Smile, there went another one.
' {$STAMP BS2}
' {$PBASIC 2.5}
'
[noparse][[/noparse] Program Description ]
'
' This program takes an external 1 Hz signal from the pulse generator and
' synthesizes a simple clock/timer. This code will run, unmodified, on and
' BS2-family module.
'
[noparse][[/noparse] I/O Definitions ]
Segs VAR OUTL ' Segments on P0 - P7
Digs VAR OUTC ' Digit control pins
Tic PIN 15 ' 1 Hz input
'
[noparse][[/noparse] Constants ]
Blank CON %00000000 ' all segments off
DecPnt CON %10000000 ' decimal point on
IsHigh CON 1
IsLow CON 0
'
[noparse][[/noparse] Variables ]
nTic VAR Bit ' new tic input
oTic VAR Bit ' old tic value
xTic VAR Bit ' change (1 when 0 -> 1)
secs VAR Word ' seconds
time VAR Word ' formatted time
theDig VAR Nib ' current display digit
'
[noparse][[/noparse] EEPROM Data ]
' .GFEDCBA
'
Digit0 DATA %00111111 ' digit patterns
Digit1 DATA %00000110
Digit2 DATA %01011011
Digit3 DATA %01001111
Digit4 DATA %01100110
Digit5 DATA %01101101
Digit6 DATA %01111101
Digit7 DATA %00000111
Using 7-Segment LED Displays · Page 69
Digit8 DATA %01111111
Digit9 DATA %01100111
DigSel DATA %1110 ' digit 0 active
DATA %1101 ' digit 1 active
DATA %1011 ' digit 2 active
DATA %0111 ' digit 3 active
'
[noparse][[/noparse] Initialization ]
Reset:
Digs = %1111 ' all off
DIRS = $0FFF ' make segs & digs outputs
'
[noparse][[/noparse] Program Code ]
Main:
DO WHILE (Tic = IsHigh) ' wait during high cycle
GOSUB Show_Clock
LOOP
DO WHILE (Tic = IsLow) ' wait during low cycle
GOSUB Show_Clock
LOOP
secs = secs + 1 // 3600 ' update current time
GOTO Main
'
[noparse][[/noparse] Subroutines ]
Show_Clock:
time = (secs / 60) * 100 ' get mins, move to 100s
time = time + (secs // 60) ' add seconds in 1s/10s
Segs = Blank ' clear display
READ (DigSel + theDig), Digs ' select digit
READ (Digit0 + (time DIG theDig)), Segs ' move digit pattern to segs
IF (theDig = 2) THEN
Segs = Segs | DecPnt ' add decimal point
ENDIF
like i said i really appreciate any input and if i should throw my begining code away "eah owell, worse things could happen.. (PUFF)"....
FOR theDig = 0 to 2
Segs = Blank
...
ENDIF
NEXT