Shop OBEX P1 Docs P2 Docs Learn Events
I/O function — Parallax Forums

I/O function

Blackbird455Blackbird455 Posts: 124
edited 2007-08-15 22:00 in General Discussion
Lets say that I wanted to have a dedicated I/O pin on an SX28 connected to a momentary pushbutton, that when pushed would cycle through (in order) , lets say, 5 different lines of code, one at a time, each push of the button would interrupt, and execute the next line (or lines) until pushed again. As in,

·When power comes on, the last set of lines that were running would begin running and continue until button is pressed, then the next set, until button is pushed, then the next set, and so on..................?????????????????????????????????

Comments

  • BeanBean Posts: 8,129
    edited 2007-08-14 22:52
    Blackbird455 said...


    ·When power comes on, the last set of lines that were running would begin running and continue until button is pressed, then the next set, until button is pushed, then the next set, and so on..................?????????????????????????????????
    The SX serial does not have any EEPROM, so you would have to have some external memory. Unless you can use SLEEP mode instead of losing power completely.

    Bean.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Teacher: What is the difference between ignorance and apathy ?
    Student: I don't know and I don't care
    Teacher: Correct !
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.hittconsulting.com
    ·
  • Blackbird455Blackbird455 Posts: 124
    edited 2007-08-14 22:53
    Ok well, forget about that , dont really need that function, but I do need an example of code to do the rest
  • JonnyMacJonnyMac Posts: 9,216
    edited 2007-08-14 22:57
    Why don't create a subroutine that waits for the button press -- you can pop that between the lines

    SUB WAIT_4BTN
      \ JB   AdvanceBtn, $        ' wait for release
      \ JNB  AdvanceBtn, $        ' wait for press
      ENDSUB
    



    This doesn't debounce the button -- but it gives you an idea to get you started.
  • Blackbird455Blackbird455 Posts: 124
    edited 2007-08-14 23:06
    yeah I will debounce with hardware,

    I am not that good with sx code yet so give me that inside of a complete set please
  • JonnyMacJonnyMac Posts: 9,216
    edited 2007-08-14 23:23
    It's really not that tough...

    HIGH RA.0
    WAIT_4BTN
    LOW RA.0
    WAIT_4BTN
    


    You have to declare the subroutine, of course. Instead of me writing a whole program for you, please crack open the help file or read the draft of "Practical SX/B" that's been posted.
  • T&E EngineerT&E Engineer Posts: 1,396
    edited 2007-08-15 22:00
    Take a look at some code I wrote (with code taken from JonnyMac and Bean). It does not use debouncing but does·wait for any of·5 or so button presses and also writes and reads a WORD variable to the EEPROM so it does not get set to 0 if power is lost. It sounds alot like what you need.

    The link has the code in it a few posts down:

    http://forums.parallax.com/showthread.php?p=660476

    Good luck.
Sign In or Register to comment.