Shop OBEX P1 Docs P2 Docs Learn Events
I/O pin selection(RE-ASSIGNMENT) — Parallax Forums

I/O pin selection(RE-ASSIGNMENT)

hmlittle59hmlittle59 Posts: 404
edited 2009-12-10 23:44 in General Discussion
Hello All,

First let me see if I can ask this were it make since. If I have (3) I/O pins assigned to (sw1,sw2,sw3) High/Low and want to RE-ASSIGN them so I only have one(1) FOR/NEXT loop, were (sw4) is either one of the other (sw1 or sw2 or sw3) pin values, will that assign pin# still be kept and can I ck that status(HIGH/LOW) in the FOR/NEXT loop?

1) sw1 Pin 1(I/O)
2) sw2 Pin 2(I/O)
3) sw3 Pin 3(I/O)

RE-ASSIGN to:

4) sw4 = sw1...or...sw4 = sw2...or...sw4 = sw3...(Can a I/O pin variable be RE-ASSIGNED to another variable and still work the same?)

will (sw4) now be ASSIGN the new I/O pin?
For I = 1 to 255
IF (sw4 = 1 ) then EXIT
NEXT I

thanks for any help

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
I'M STILL LEARNING SO MUCH...BUT STILL KNOW SO LITTLE!!!

hmlittle59

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-12-09 19:09
    If the I/O pins are sequential (like pins 4, 5, and 6), you can already access them the way you want since all 16 input pins are actually the 16 bits of a word variable INS. This is described in detail in the BASIC Stamp Syntax and Reference Manual. You could do something like:

    for i = 4 to 6
    if ins.bit(i) = 1 then exit
    next i

    The direction bits and output pins are handled similarly. Again, read the manual in the section on memory.
  • hmlittle59hmlittle59 Posts: 404
    edited 2009-12-09 19:51
    Hello Mike,

    I did explain it clear enough. Let me re-word it after I go and read the memory section first though. It's more about variable re-assignment then pin location

    thanks Mike

    Howard

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I'M STILL LEARNING SO MUCH...BUT STILL KNOW SO LITTLE!!!

    hmlittle59
  • Mike GreenMike Green Posts: 23,101
    edited 2009-12-09 20:17
    You can define alternate names for a variable (or I/O pin) by using what's called an "alias", but this happens when the program compiles. You can't change this when the program is running. Look up "alias" in the Manual. It's not clear what you mean by "re-assignment" although it sounds like you want to change what I/O pin is associated with a variable name while the program is running and there's no way to do that in PBasic.
  • hmlittle59hmlittle59 Posts: 404
    edited 2009-12-10 02:59
    Thanks Mike,

    That's the word I was looking for...now I'm stuck again. I'll have to find some other way to skin this cat.

    thanks again

    maybe I'll learn to use CASE statements

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I'M STILL LEARNING SO MUCH...BUT STILL KNOW SO LITTLE!!!

    hmlittle59
  • Mike GreenMike Green Posts: 23,101
    edited 2009-12-10 03:19
    I still don't understand what you're trying to do that can't be done using bit arrays like I showed earlier. You can define bit array variables as well, they don't have to be I/O pins. Again, look at the part of the Stamp Manual that discusses the use of memory.
  • hmlittle59hmlittle59 Posts: 404
    edited 2009-12-10 04:36
    I'm out of variable space.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I'M STILL LEARNING SO MUCH...BUT STILL KNOW SO LITTLE!!!

    hmlittle59
  • Mike GreenMike Green Posts: 23,101
    edited 2009-12-10 04:42
    Ah!

    In that case, aliases are what you need to use. You also have to be creative in how you use variables. Make sure you're using the smallest units that work (bits, nibs, bytes, words). Sometimes making a table of variables with the names of the routines where they're used will help you identify when they're not needed. Sometimes recoding some routines will free up a little bit of storage. If you have a small loop you may be able to eliminate a FOR loop by repeating the code using constants instead of an index variable.
  • hmlittle59hmlittle59 Posts: 404
    edited 2009-12-10 23:41
    Hello Mike,

    I've been using all variables over and over again....no variable is SAFE!!! I have about 4 that I can't mess with though and some are saved into DS1302 RAM and Reloaded/Refreshed before returning to the Main Menu. I've only done some programming with (bits,nibs) in 6502 Assembly code way back when...So that will be a re-training if I go that route. I set some flags to let me know were I'm coming from in the Code now and I thought it through last night and it may work if I try it but it looked MESSY in my HEAD but I don't know how it will work once I get it Coded. I do still need to read about Alias though.


    thanks Mike

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I'M STILL LEARNING SO MUCH...BUT STILL KNOW SO LITTLE!!!

    hmlittle59
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-12-10 23:44
    Please post the code that you are working on we might be able to help you with it

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

    ·
    ·
    ·
    ·
    Sam
Sign In or Register to comment.