Nested timing and control
pcleats
Posts: 11
Hello all,
I am working on a project that requires some nested timing and control. I am not sure of the best way to do this so any help is appericated. The following is a run down of what I need the BS2 to do.
The way I need it to function is as follows
When the start solenoid button is pressed then the start solenoid is engaged for 30 minutes to allow the battery to charge while traveling to a location
if during this time the start button is pressed then the start solenoid is disengaged and the system enters the initialization and start up.
after 30 minutes the start solenoid timer will turn off the solenoid this will prevent the car from being hot wired or other wise started
I also have a timing issue where if a door is opened then a set of IR leds will come on the illuminate the inside of the car I also need to start a timer that will turn on an additional lamp after 2 minutes. In addition if the door is left ajar for say 30 minutes I need the system to turn off the IR leds to prevent excessive current draw.
I have included the code I currently have.
Any help would be greatly appericated.
Patrick Christensen
'
' I/O Definitions
'
SwInputs VAR INA 'Door switch inputs pins 0-3
Startswitch CON 4 'Starts the system this switch is the Hazard lamp switch
SolenoidSwitch CON 5 'Solenoid Engage Switch
MotionInput CON 6 'Motion Sensor Input pin 4
IRleds CON 15 'Will come on if doors or internal motion is detected
Start_Solenoid CON 14 'This is for the start Solenoid
Templed CON 13 'Will come on when system starts
HitLight CON 12 'Will come on if motion is detected inside the car
'
' Variables
'
Start_Switch_Data VAR Byte 'Variable for the Button Command
Start_Solenoid_Data VAR Byte 'Variable for start solenoid
Door_Switches VAR Nib 'Where the data for the switches is stored
Wait_Timer VAR Nib 'Timing Variable
Loop_Counter VAR Word 'This is for the Solenoid timing
Main:
BUTTON SolenoidSwitch, 0, 255, 10, Start_Solenoid_Data, 1, Solenoid_On 'Engages the start solenoid
BUTTON Startswitch, 0, 255, 10, Start_Switch_Data, 1, Start 'Waits for start switch to be pressed
GOTO main
Solenoid_On:
HIGH Start_solenoid
Start:
' LOW Start_Solenoid
HIGH Templed
GOSUB Get_switches
DEBUG HOME, "Inputs = ",IBIN4 Door_switches
PAUSE 50
GOTO start
END
Get_switches: 'This section will test the state of the switches and will turn on
Door_Switches = %1111 'the IR leds as long as the door is open
FOR Wait_Timer = 1 TO 10
Door_Switches = Door_Switches & ~Swinputs
PAUSE 5
NEXT
IF Door_switches <> 0000 THEN GOSUB irlighton
IF Door_switches = 0000 THEN GOSUB irlightsoff
RETURN
irlighton:
HIGH irleds
RETURN
irlightsoff:
LOW irleds
RETURN
'
'
what I need it to do
'The way it works right now you should understand
'The way I need it to function is as follows
'1. The start solenoid is engaged for 30 minutes to allow the battery to charge while traveling to a location
'if during that time the car is placed and the start button is pressed then the system will begin functioning
'after 30 minutes the solenoid timer will turn off the solenoid this will prevent the car from being hot wired
'or other wise started
'What I am not quite sure of is can the BS2 do what I need it to do?
I am working on a project that requires some nested timing and control. I am not sure of the best way to do this so any help is appericated. The following is a run down of what I need the BS2 to do.
The way I need it to function is as follows
When the start solenoid button is pressed then the start solenoid is engaged for 30 minutes to allow the battery to charge while traveling to a location
if during this time the start button is pressed then the start solenoid is disengaged and the system enters the initialization and start up.
after 30 minutes the start solenoid timer will turn off the solenoid this will prevent the car from being hot wired or other wise started
I also have a timing issue where if a door is opened then a set of IR leds will come on the illuminate the inside of the car I also need to start a timer that will turn on an additional lamp after 2 minutes. In addition if the door is left ajar for say 30 minutes I need the system to turn off the IR leds to prevent excessive current draw.
I have included the code I currently have.
Any help would be greatly appericated.
Patrick Christensen
'
' I/O Definitions
'
SwInputs VAR INA 'Door switch inputs pins 0-3
Startswitch CON 4 'Starts the system this switch is the Hazard lamp switch
SolenoidSwitch CON 5 'Solenoid Engage Switch
MotionInput CON 6 'Motion Sensor Input pin 4
IRleds CON 15 'Will come on if doors or internal motion is detected
Start_Solenoid CON 14 'This is for the start Solenoid
Templed CON 13 'Will come on when system starts
HitLight CON 12 'Will come on if motion is detected inside the car
'
' Variables
'
Start_Switch_Data VAR Byte 'Variable for the Button Command
Start_Solenoid_Data VAR Byte 'Variable for start solenoid
Door_Switches VAR Nib 'Where the data for the switches is stored
Wait_Timer VAR Nib 'Timing Variable
Loop_Counter VAR Word 'This is for the Solenoid timing
Main:
BUTTON SolenoidSwitch, 0, 255, 10, Start_Solenoid_Data, 1, Solenoid_On 'Engages the start solenoid
BUTTON Startswitch, 0, 255, 10, Start_Switch_Data, 1, Start 'Waits for start switch to be pressed
GOTO main
Solenoid_On:
HIGH Start_solenoid
Start:
' LOW Start_Solenoid
HIGH Templed
GOSUB Get_switches
DEBUG HOME, "Inputs = ",IBIN4 Door_switches
PAUSE 50
GOTO start
END
Get_switches: 'This section will test the state of the switches and will turn on
Door_Switches = %1111 'the IR leds as long as the door is open
FOR Wait_Timer = 1 TO 10
Door_Switches = Door_Switches & ~Swinputs
PAUSE 5
NEXT
IF Door_switches <> 0000 THEN GOSUB irlighton
IF Door_switches = 0000 THEN GOSUB irlightsoff
RETURN
irlighton:
HIGH irleds
RETURN
irlightsoff:
LOW irleds
RETURN
'
'
what I need it to do
'The way it works right now you should understand
'The way I need it to function is as follows
'1. The start solenoid is engaged for 30 minutes to allow the battery to charge while traveling to a location
'if during that time the car is placed and the start button is pressed then the system will begin functioning
'after 30 minutes the solenoid timer will turn off the solenoid this will prevent the car from being hot wired
'or other wise started
'What I am not quite sure of is can the BS2 do what I need it to do?
Comments
Instead of using the "BUTTON" command, I think that the "IF THEN" command will work for this project.· The "IF THEN" command·is able to read in inputs.· You can find more information about the "IF THEN" commands in the BASIC Stamp Manual version 2.0.· Here is a link for the manual download:
http://www.parallax.com/html_pages/downloads/basicstamps/documentation_basic_stamp.asp
Regards,
Dave