Shop OBEX P1 Docs P2 Docs Learn Events
Locked out of main body while executing sub routine. — Parallax Forums

Locked out of main body while executing sub routine.

ZeusZeus Posts: 79
edited 2012-04-21 08:27 in BASIC Stamp
To all,

I am building an alarm clock and I am having a problem where my program gets tied up while it is executing the alarm sub-routine. Simply put, while the alarm is playing its 2 second loop it cannot scan for the button which that shuts it off. The user has to hold down the button, which terminates the alarm sub-routine, for the duration of the 2 second loop in order register the input and therefore to exit the sub-routine.

Is there a way around this with code? If not I am thinking that I will have to use a relay.

Actually now that I think about it my above title is incorrect, my problem is not that I am locked out of the main body it is that I am only able to exit the alarm tone loop at a very specific point, but in any event that is my problem.

Thank you in advance,

Zeus

Comments

  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-04-21 07:32
    You'd need to make your alarm a series of shorter sounds and check for the button press between the short sound bursts.

    Another option would be to use an external (to the Stamp) sound making device that the Stamp can start and stop.
  • SRLMSRLM Posts: 5,045
    edited 2012-04-21 07:40
    What about something like this:
    WHILE done == false AND in[button] == false
        {Play sound}
    

    Although my syntax might be a bit off (I haven't done PBASIC in a while) the principle is the same. In your loop test for the button. It shouldn't create much of a delay and it will allow the user to exit at any point.
  • ZeusZeus Posts: 79
    edited 2012-04-21 08:04
    Duane,

    Yes I though about that but there has to be a more elegant solution. I will give SRLM's solution a try and see what results.

    Thanks for both of your suggestions.

    Zeus
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-04-21 08:14
    SRLM and my suggestions are pretty much the same thing. They both require short sound bursts with a button check between each burst.

    If you use the normal two second sound code in the place of "{Play sound}" the button still wont be able to interupt the sound.
  • ZeusZeus Posts: 79
    edited 2012-04-21 08:27
    Duane,

    Okay, I missed that. I will have to look into and see what is possible. Thanks for the help.

    Zeus
Sign In or Register to comment.