This is code for use with a BASIC based compiler. It's intended for use with PIC12C508/509/608/609 or 12F508/509/608/609 microcontrollers, but could be modified to work with other mcu's. GPIO.0 = pin 7 of the PIC on around to GPIO.4 which would be pin 3. GPIO.5 would be pin2, but we aren't using it. You could swap the variables around if you need to.
This is for use with either a single latching or double latching relay such as the TQ2-L-5V or TQ2-2L-5V. If you find that the relay is in bypass with the LED is on, just switch the LATCH0 and LATCH1 variables.
Code:
LATCH0 var GPIO.1
LATCH1 var GPIO.2
LED var GPIO.4
MUTE var GPIO.0
PB Var GPIO.3 ' Alias GPIO.3 to push button
LEDon var bit
LEDoff var bit
LEDoff = 0
LEDon = 1
ANSEL = 0 ' Set all digital
CMCON0 = 0 ' Analog comparators off
TRISIO = %11001000
LED = 0
LATCH0 = 0
MUTE = 0
LATCH1 = 1 'initiate program in bypass with LED off
pause 10 'pulse to initiate latch1 on
LATCH1 = 0 'bypass then turn off to save power
main:
if PB = 0 then
MUTE = 1 'mute while switching occurs
pause 40 'mute & debounce
gosub LEDstatus
pause 10 'allow 10ms pulse to actuate relay
LATCH1 = 0 'end pulse to relay to save power
LATCH0 = 0
pause 40 'allow another 40ms to mute
MUTE = 0
gosub switchrelease
pause 30 'debounce
endif
goto main
End
LEDstatus: 'toggle LED status & bypass
if LED = 1 then
LED = LEDoff
LATCH0 = LEDoff
LATCH1 = LEDon
elseif LED = 0 then
LATCH1 = LEDoff
LED = LEDon
LATCH0 = LEDon
endif
return
switchrelease: 'wait for footswitch to be released
do until PB = 1
pause 5
loop
return
_________________
*patience is a virtue*
Please do not PM me. email is prefered.
keith@buildyourownclone.com