Shop OBEX P1 Docs P2 Docs Learn Events
2 program in one BS2 — Parallax Forums

2 program in one BS2

irivineirivine Posts: 18
edited 2009-01-21 03:04 in BASIC Stamp
Currently i am working on a project that uses BS2 , having 2 program ...

i am adding a slide switch to pin 1 of bs2 which will enable me to switch between 2 program for example when pin 1 = 1 , it will go to routine 1 , if not i will goto routine 2

i wonder if this actually works , because i am having some problem that the programs are not switching
i wonder if this doesn't work because the voltage to the switch is not hign enough for the pin to be 1
could the way i am putting the switch affecting the program switching

help need ! thanks !!smile.gif

the following is the code i am doing

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-01-20 14:37
    Look at the chapter in the Stamp Basic Syntax and Reference Manual on the BUTTON statement. There are diagrams of how to hook up a pushbutton (or slide switch) to a Stamp. You probably need a "pullup" resistor as shown there.

    It's not very helpful to say "actually works" or "doesn't work" or "some problem". It's much more useful to say what appears to happen to the program when the switch is in one setting or the other setting like "When I set the switch so it connects the I/O pin to ground, the program takes the proper path. When I set the switch to the other setting, it takes the wrong path.".
  • irivineirivine Posts: 18
    edited 2009-01-20 15:40
    oh , thanks for the mention on the button

    so in this case , i use a pushbutton with the active-high circuit

    and with the following code


    Main:
    if(pin 1 = 1) GOTO ROUTINE ONE ELSE GOTO ROUTINE TWO

    ROUTINE ONE:

    RETURN

    ROUTINE TWO:

    RETURN

    will this work ?
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-01-20 22:34
    irivine

    You can have two routines

    This is what I have found is if your routines are very different then you will have a lot of trouble getting this to work unless you only change the routines at Power Up

    This is an example of what I am talking about

    (Power_ON·)··is different form·(·Power_OFF )·

    power_on has power
    and
    power_off dose not power

    This is for I\O pin 14· (·IN14 )·


    Pick_ONE:
    DO
    DEBUG CLS
    IF IN14 = 0 THEN
    ·· GOSUB Power_ON
    ELSE
    ·· GOSUB Power_OFF
    ENDIF
    LOOP

    Power_ON:
    ·
    DO WHILE IN15 = 1
    ·
    GOSUB Show_Time
    GOSUB Show_State_Power_ON
    LOOP

    DO WHILE IN15 = 0
    ·
    GOSUB Halt_clock
    GOSUB Display_Time
    GOSUB Show_State_Power_ON
    ·LOOP
    ·
    GOSUB Restart_clock
    GOSUB Power_Restarts
    GOSUB Power_ON
    RETURN


    Power_Off:
    DO
    ·GOSUB Show_Time
    ·GOSUB Show_State_Power_OFF
    ·
    ·LOOP UNTIL IN15 = 1

    ·DO
    ·GOSUB Display_Time

    ·GOSUB Halt_clock
    ·GOSUB Show_State_Power_OFF
    ·
    LOOP UNTIL IN15 = 0
    ·
    GOSUB Restart_clock
    GOSUB Power_restarts:
    GOTO Power_Off
    RETURN
    ·

    Show_State_Power_ON:
    DEBUG "· Show_State_Power_ON· "


    ·IF IN15 = 0 THEN

    ·SEROUT LCD, Baud, [noparse][[/noparse]DispLightOff]
    PAUSE 1


    ELSEIF IN15 = 1 THEN

    SEROUT LCD, Baud, [noparse][[/noparse]DispLightOn]
    PAUSE 1
    ENDIF
    DEBUG DEC3 restarts, "·· r"
    RETURN


    Show_State_Power_OFF:
    DEBUG "· Show_State_Power_OFF· "


    ·IF IN15 = 0 THEN

    ·SEROUT LCD, Baud, [noparse][[/noparse]DispLightOn]
    PAUSE 1


    ELSEIF IN15 = 1 THEN

    SEROUT LCD, Baud, [noparse][[/noparse]DispLightOff]
    PAUSE 1
    ENDIF


    Halt_clock:
    ·reg = $80········· ' Point to register 80h
    ·ioByte = %10000000 ' Set Clock Halt Bit
    ·GOSUB RTC_Out····· ' Send Command
    ·RETURN


    Restart_clock:
    ·reg = $80········· ' Point to register 80h
    ·ioByte = %0110000 ' starts the clock by clearing the Clock Halt bit and clears the minutes to "00"
    ·GOSUB RTC_Out····· ' Send Command
    ·RETURN

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 1/25/2009 2:06:36 AM GMT
  • irivineirivine Posts: 18
    edited 2009-01-21 03:04
    so the in14 is the indication of whether the bs2 is on/off ?

    sry i am still now sure what is it about

    so i must always have the halt_clock and restart_clock no matter what i

    currently i am still a secondary school student

    can i have some guidance with reference to my circuit?

    thank you for ur help
Sign In or Register to comment.