PDA

View Full Version : pot to display to relay



spuddudit
02-19-2010, 07:29 AM
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

Mike Green
02-19-2010, 07:52 AM
As with all questions like this, please attach the source code you're working with to your message along with a schematic of your setup. A scanned in drawing is adequate for the schematic.

spuddudit
02-19-2010, 08:46 AM
dont realy have code yet like i said i was working with stamp works literature, here is what i started with though; it shows nothing about the LEDS the need to flash.

' {$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, <= [50, 100, 150, 200, 250, 300, 350, 400, 450, 500, 550, 600,
650, 700, 750, 800 ], index

LOOKUP index, [ %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

Spiral_72
02-19-2010, 09:08 AM
If you have the number in some variable, you can separate the number 10 or 12 or 99 into digits by:

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"...... crap, there went another one.

spuddudit
02-19-2010, 09:24 AM
how would that work with my current code? or how do i know what the pot reads? ( what i tell it to display?) sorry there for a bit i kinda though i was pretty good with the project in the " whats a micro controller book" then i started on " stamp works" gets pretty in depth in a hurry....

spuddudit
02-19-2010, 09:25 AM
also how do i tell it when 60 is displayed to pause 6000 between LED flashes?

Spiral_72
02-19-2010, 11:43 AM
Hmmm, well the pot value would be a function of your "time" variable. You'll probably have to scale it in some way to get what you want by multiplication or division...... but in my code, counter = time.

"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"...... crap, there went another one.

spuddudit
02-19-2010, 11:59 AM
well i dont really have much displaying at all, i can get 0-9 to display on one or both displays by turning the commons high/low. butif you have code ideas that i can play with i would really appreciate it i kinda just grabbed something offline to start with but i think its going to have to be something more like: ( with sub-rutines to do the display side)
' {$STAMP BS2}
' {$PBASIC 2.5}
' -----[ 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.
' -----[ I/O Definitions ]-------------------------------------------------
Segs VAR OUTL ' Segments on P0 - P7
Digs VAR OUTC ' Digit control pins
Tic PIN 15 ' 1 Hz input
' -----[ Constants ]-------------------------------------------------------
Blank CON %00000000 ' all segments off
DecPnt CON %10000000 ' decimal point on
IsHigh CON 1
IsLow CON 0
' -----[ 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
' -----[ 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
' -----[ Initialization ]--------------------------------------------------
Reset:
Digs = %1111 ' all off
DIRS = $0FFF ' make segs & digs outputs
' -----[ 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
' -----[ 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)"....

Mike Green
02-19-2010, 12:42 PM
Where do you ever set "theDig"? Like all variables, it's initialized to zero. How about using a FOR / NEXT loop in Show_Clock?

FOR theDig = 0 to 2
Segs = Blank
...
ENDIF
NEXT

spuddudit
02-19-2010, 01:51 PM
i am not at all familiar with the "theDig" command can you send a link so i can read up some? i guess maybe more basic terms for me, wow no i just straight up feel tarded.... lol thanks

Mike Green
02-19-2010, 01:59 PM
"theDig" is not a command. If you look at your program, you'll see that you've declared it as a variable.