Shop OBEX P1 Docs P2 Docs Learn Events
Keyboard interrupt — Parallax Forums

Keyboard interrupt

StampmysterStampmyster Posts: 27
edited 2011-02-28 20:48 in BASIC Stamp
I’m aware that a button can be used to allow a program to branch in real-time, as an assigned-pin can be monitored to see it the button was pressed or not, all the while the program continues to run.

-The program is not stopped waiting for input, like when using DEBUGIN command.-

Is there a way to monitor the keyboard to do the same? For instance, in the debug window have it read; “To flash blue light hit any key”, all the while the program continues to run until a key is pressed. It will then branch to the flash-blue-light routine without pausing the program first.

Perhaps there is a way to read the keyboard buffer itself? Or use a null?

For some reason, I think I have seen it before somewhere, and may be fundamental?

Thanks!

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2011-02-28 15:54
    Not really. There is no keyboard buffer. When you do a SERIN (or DEBUGIN), the PBasic interpreter stops until a character is received. You can use a timeout on the SERIN so the program can continue if there's nothing that comes in, but any characters that come in when other statements are executing are ignored completely.

    It's possible to add an external serial interface. I think Microchip makes one (MAX3400?). That would let you do what you're describing.
  • StampmysterStampmyster Posts: 27
    edited 2011-02-28 16:13
    Yes,

    I did investigate the SERIN command and actually thought about using the timeout parameter. I will try again. (I never used the timeout before and unfamiliar.)

    I will also look into the Microchip max3400...

    Thank you kindly!
  • StampmysterStampmyster Posts: 27
    edited 2011-02-28 20:48
    It looks like the SERIN command will do the trick. And yes, as you say, there is a few seconds of “Dead-Air”. But, my application can accommodate it nicely.

    I want the option to access my EEPROM manually on start-up. If there is a reset, and no one is around, it will still restart normally, and not wait indefinitely.

    If I hit any key during the waiting period, it will branch to a new program.

    If I decide to do nothing, the Main-Program simply continues after a few seconds:

    I created an example, for others if they might find it useful.


    ' {$STAMP BS2}
    ' {$PBASIC 2.0}

    ‘This program allows a user a few seconds to decide (whether or not) to branch off to a
    ‘sub-routine, and if nothing is entered it simply continues with the Main-Program.

    result VAR Word

    begin:

    DEBUG CLS, "You have three secs to hit any key to access EEPROM.", CR

    SERIN 16, 16468, 3000, No_Data, [result]

    DEBUG " = ", DEC result
    DEBUG CR, CR, "You have now paused the Main_Program,", CR
    DEBUG "and entered the EEPROM_Access_Tool."

    END

    No_Data:

    DEBUG CR, "You have decided not pause the Main_Program,"
    DEBUG CR, "and Main_Program will now continue."

    PAUSE 5000 : GOTO begin


    Thanks Mr. Green!
Sign In or Register to comment.