Forgive me for probably not using the correct terms, but I'm wondering if there's an easy way to do something in arduino code that i'm not aware of.
I'm running multiple fram cards, in order to write to them you call a command like
fram1.write8(b+maxb, swayFRAM);
where fram1 is the name of the initialized fram card at the top of the code. So, in some cases you could have:
fram1.write8(b+maxb, swayFRAM);
fram2.write8(b+maxb, swayFRAM);
and write to two different fram cards. However, in my code, I have a need for a conditional. For example:
"If I push button X, I'd like to write all my data to fram card 2. If I don't push button X I'd like to write to fram card 1."
Obviously you could do
Code: Select all
if (button == 1)
{ fram1.write8(b+maxb, swayFRAM);
}
else
{ fram2.write8(b+maxb, swayFRAM);
However, my code is more like "I'm going to push a button at the beginning of the looooong code and any time you see a fram write command, I want it to fram card 1. If it's not pushed I was all the fram write codes to refer to fram card 2.
Is there a way to put something like:
Code: Select all
void loop(){
*read button input*
if(button==1)
{xxx = fram1;
}
else
{xxx=fram2;
}
xxx.write8(b+maxb, swayFRAM);
**do some other stuff**
xxx.write8(b+maxb, swayFRAM);
} //end loop
I hope I am being clear. I know you can do a #define at the top of code to define the value of an actual variable ithe code. However, does that work with function calls? I need the xxx to have the ability to be redefined as the program loops as we check to see if the button is pushed on not.
Id rather not have to do it the long way and write a IF THEN around each time I use a fram.write8 command. That seems like a terribly inefficient way to go.
Thanks for any help you can provide.
-Jim