Here's the code we're working on to use up and down buttons with the Stamp so you don't have to type in new numbers every time to change the pulse time. Attach the transistors to pins other than 14, 15. If you want to change the starting value or the amount of the Increment/Decrement, change it in the CON line. For those of you who do NOT have your chip attached to a board and have to pull it to reprogram it every time, something like this might be extremely useful because it would allow you to change values on the fly.
' Start pulsing two transistors with a default time
' Increment the time each time P4 button pressed
' Decrement the time each time P3 button pressed
' {$STAMP BS2}
' {PBASIC 2.5}
DefPulse CON 5000 'Default PULSOUT time ( x 2 us. = 10000 us. = 10 ms.)
PulseIncr CON 10 'Amount to increment/decrement ( x 20 us. = 20 us.) on
' each button push
Pulse VAR Word 'Current pulse time (in units of 2 us.)
Pulse = DefPulse
GOSUB DisplayPulse
DO
PULSOUT 14, Pulse 'May need to change this and next Pin number
PULSOUT 15, Pulse
IF (IN3 = 1) THEN 'IN3 is the bottom of the two buttons, so, going down
Pulse = Pulse - PulseIncr
GOSUB DisplayPulse
ELSEIF (IN4 = 1) THEN 'IN4 is the top of the two buttons, so, going up
Pulse = Pulse + PulseIncr
GOSUB DisplayPulse
ENDIF
LOOP
DisplayPulse: 'Subroutine to display laest value of the PULSOUT duration
DEBUG HOME 'Return the cursor to the top, left of screen
DEBUG "PULSOUT Duration is ", Pulse, "( x 2 us.) "
RETURN
END
David
' Start pulsing two transistors with a default time
' Increment the time each time P4 button pressed
' Decrement the time each time P3 button pressed
' {$STAMP BS2}
' {PBASIC 2.5}
DefPulse CON 5000 'Default PULSOUT time ( x 2 us. = 10000 us. = 10 ms.)
PulseIncr CON 10 'Amount to increment/decrement ( x 20 us. = 20 us.) on
' each button push
Pulse VAR Word 'Current pulse time (in units of 2 us.)
Pulse = DefPulse
GOSUB DisplayPulse
DO
PULSOUT 14, Pulse 'May need to change this and next Pin number
PULSOUT 15, Pulse
IF (IN3 = 1) THEN 'IN3 is the bottom of the two buttons, so, going down
Pulse = Pulse - PulseIncr
GOSUB DisplayPulse
ELSEIF (IN4 = 1) THEN 'IN4 is the top of the two buttons, so, going up
Pulse = Pulse + PulseIncr
GOSUB DisplayPulse
ENDIF
LOOP
DisplayPulse: 'Subroutine to display laest value of the PULSOUT duration
DEBUG HOME 'Return the cursor to the top, left of screen
DEBUG "PULSOUT Duration is ", Pulse, "( x 2 us.) "
RETURN
END
David
Comment