Updated w/video Please check and see if this is correct.
Yes ... this is for my motorcycle ... LOL.
This is the final code ... working and this is a link to a demo video on YouTube:
http://www.youtube.com/watch?v=2R_BpnwrI-0
I have the following conditions and am using a small FET with a pull-up on the Picaxe for the signal input and the brake input. I am using a logic level FEAT to switch ground to a flasher module for the turn signal. I built the circuit and it works manually but I do not know if it will work with this code ... please set me straight ... I am quite poor at this!
Power up the Picaxe signal line = 0
Signal activated Picaxe signal line = 1 then it alternates 10101010 50% duty cycle
When the Picaxe times out, ground is removed and the Picaxe Signal line =1 steady
When the switch is manually reset the Picaxe signal line = 0 and needs to be ready for the next event.
My idea is to basically start a timer that will turn them off in XX time unless it is reset by activating the brake switch (instead of clutch). If the user cancels the turn signal manually then it ends the event and waits for another one. If the Picaxe times out then the user is required to manually reset the switch for another event to occur. (this is actually done when the next turn is signaled because of the way the switch is made).
Here is my code.
Yes ... this is for my motorcycle ... LOL.
This is the final code ... working and this is a link to a demo video on YouTube:
http://www.youtube.com/watch?v=2R_BpnwrI-0
Code:
#picaxe 08M
#rem
####################################################
# Automatic Turn Signal Cancellation Code: #
# #
# Code Version :1C #
# Date :August 2010 #
# PICAXE Type :8M #
# Firmware :> 9.2 #
# Editor Software :5.2.0 #
####################################################
#endrem
'############################################################################
'# MAIN ROUTINE #
'############################################################################
Symbol Signal = Pin3 '(pin4)
Symbol Brake = Pin4 '(pin3)
Symbol FlashEnable = 0 '(pin7)
Symbol Warning = 2 '(pin5)
Symbol Flash_ON_Timer = 25 'number of ~1/2 second cycles until indicator is auto cancelled
Symbol Debounce = 25 '20 ms @ 4MHz. This is the time to allow switch contacts to settle.
Symbol Last_Flashing_Signal = bit0
Symbol Counter = b1
Symbol Flash_Time = b2
SYMBOL Turn_Active = 1
SYMBOL TurnOff = 0
SYMBOL Brake_Applied = 0
Ready:
Do 'Wait for turn signal activation
Last_Flashing_Signal = 0
Flash_Time = 0
High FlashEnable 'Enable the flasher module
If Signal = Turn_Active then Start 'Signal switch has been activated
Pause Debounce
Loop UNTIL Signal = Turn_Active 'Loop until the Turn Signal has been activated.
Start:
CheckForFlasherToggling:
DO
Pause 500
If Brake = Brake_Applied then 'User has applied the brakes
Pause Debounce
Flash_Time=0
Endif
If Signal <> Last_Flashing_Signal Then ' Check to see if the Signal line is toggling
Last_Flashing_Signal = Last_Flashing_Signal ^ 1
End If
Inc Flash_Time 'Increment the Flash ON time counter
LOOP UNTIL Flash_Time = Flash_ON_Timer 'Continue to flash until the timer expires
Turn_Off:
Do
Low FlashEnable 'Turn off the signal module
For Counter = 0 to 15
If Signal = Turn_Active then 'Wait 20 seconds then send a warning signal
Pause 1000
Next
Tune 0, 4,($1A,$50,$1A,$50,$1A,$50) 'Sound warning
Else Goto ready ' User has reset the manual switch
Endif
Loop while Signal = Turn_Active 'Wait until switch is reset by user
Goto Ready
I have the following conditions and am using a small FET with a pull-up on the Picaxe for the signal input and the brake input. I am using a logic level FEAT to switch ground to a flasher module for the turn signal. I built the circuit and it works manually but I do not know if it will work with this code ... please set me straight ... I am quite poor at this!
Power up the Picaxe signal line = 0
Signal activated Picaxe signal line = 1 then it alternates 10101010 50% duty cycle
When the Picaxe times out, ground is removed and the Picaxe Signal line =1 steady
When the switch is manually reset the Picaxe signal line = 0 and needs to be ready for the next event.
My idea is to basically start a timer that will turn them off in XX time unless it is reset by activating the brake switch (instead of clutch). If the user cancels the turn signal manually then it ends the event and waits for another one. If the Picaxe times out then the user is required to manually reset the switch for another event to occur. (this is actually done when the next turn is signaled because of the way the switch is made).
Here is my code.
Code:
#picaxe 08M
#rem
####################################################
# Automatic Turn Signal Cancellation Code: #
# #
# Code Version :1A #
# Date :August 2010 #
# PICAXE Type :8M #
# Firmware :> A.2 #
# Editor Software :5.2.0 #
####################################################
#endrem
'############################################################################
'# INITIALIZE #
'############################################################################
'Set 8MHz clock source.
Setfreq m8
'############################################################################
'# MAIN ROUTINE #
'############################################################################
Symbol Signal = Input3 '(pin4)
Symbol Ground = 0 '(pin7)
Symbol Brake = Input2 '(pin5)
Symbol Timer = 15
Symbol Debounce = 25 '25 ms @ 8MHz.This is the time to allow switch contacts to settle.
Symbol Time = b0
Symbol Count_Total = b1
Symbol Counter = b2
Symbol Flash_Time = b3
Ready:
Do 'Wait for turn signal activation
Counter = 0
High Ground
If Signal = 1 then Start 'Signal has been activated.
Pause Debounce
Loop
Start:
Reset:
For Flash_Time = 0 to Timer 'Start a counter to run 10 seconds
If Brake = 0 Then Reset 'Brake has been activated
Count 4, 500, b2
Count_total = Counter + Count_total
if Counter > Count_Total then Ready 'Signal has been canceled by user
Next
Turn_Off:
Do
Low Ground 'Turn off the signal
Loop while Signal = 1 'Wait until switch is reset by user
Goto Ready
Last edited: