WHat i wanted was to have _read read the outputs of the ram and have _read = the output ex: out = 1101; _read = 13;
If that's what you wanted, why does it return zero?
Your _write method also (unusually) returns a value that is always zero.
I changed, but still has an error, do i have to have it do: return _rbits; ?
Did you initialise _rbits?
how?
as in int _rbits?
No, apart from the missing semicolon, that looks more like a declaration, not an initialisation.
The clue is, you did initialise a variable, but it wasn't _rbits.
so, how should i do it?
I'd probably forget about _rbits altogether, and use (I mean really use) "rv".
ok, ill try it.
By the way, the spelling is "indeterminate", not "intermediate".
this is what i have, what should i change?
int AM9111::read(unsigned int address)
{
int rv = 0;
_read() = rv;
_setAddress(address);
return rv;
}
int AM9111::_read()
{
int rv = 0;
digitalWrite(_odp,0);
digitalWrite(_wep,1);
bitWrite(rv,0,digitalRead(_IO[0]));
bitWrite(rv,1,digitalRead(_IO[1]));
bitWrite(rv,2,digitalRead(_IO[2]));
bitWrite(rv,3,digitalRead(_IO[3]));
_read() = rv;
}
_read() = rv;
I thought we'd already decided that this was a no-no?
int AM9111::read(unsigned int address)
{
int rv = 0;
_read() = rv;
_setAddress(address);
return rv;
}
Is that really the correct order of events?
farlepet:
int AM9111::_read()
{
digitalWrite(_odp,0);
digitalWrite(_wep,1);
int rv = 0;
bitWrite(_rbits,0,digitalRead(_IO[0]));
bitWrite(_rbits,1,digitalRead(_IO[1]));
bitWrite(_rbits,2,digitalRead(_IO[2]));
bitWrite(_rbits,3,digitalRead(_IO[3]));
_read() = _rbits;
return rv;
}
Someone's been doing too much Visual Basic.
Instead of:
_read() = _rbits;
return rv;
You want:
return _rbits;
Although I'm not sure what rv does. Did you put it there to make compiler errors go away?
farlepet:
int AM9111::_read()
{
digitalWrite(_odp,0);
digitalWrite(_wep,1);
int rv = 0;
bitWrite(_rbits,0,digitalRead(_IO[0]));
bitWrite(_rbits,1,digitalRead(_IO[1]));
bitWrite(_rbits,2,digitalRead(_IO[2]));
bitWrite(_rbits,3,digitalRead(_IO[3]));
_read() = _rbits;
return rv;
}
I still don't totally get this. Are you trying to change _rbits? In which case why return anything from the function? In that case you want:
void AM9111::_read()
{
digitalWrite(_odp,0);
digitalWrite(_wep,1);
_rbits = 0;
bitWrite(_rbits,0,digitalRead(_IO[0]));
bitWrite(_rbits,1,digitalRead(_IO[1]));
bitWrite(_rbits,2,digitalRead(_IO[2]));
bitWrite(_rbits,3,digitalRead(_IO[3]));
}
But if you want to return stuff, and not affect things such as _rbits (have side-effects) then you actually want:
int AM9111::_read()
{
digitalWrite(_odp,0);
digitalWrite(_wep,1);
int rv = 0;
bitWrite(rv,0,digitalRead(_IO[0]));
bitWrite(rv,1,digitalRead(_IO[1]));
bitWrite(rv,2,digitalRead(_IO[2]));
bitWrite(rv,3,digitalRead(_IO[3]));
return rv;
}
Thanks, ill try it
Yes! It finally compiled! I will upload it tomorrow morning and try it.
Thanks for all your help
And what do you mean by "Someone's been doing too much Visual Basic"?
Well, have you done Visual Basic?
In VB, a function returns its results by assigning to the function name. For example:
function foo (a, b)
foo = a + b ' return result of adding a to b
end function
So when I saw you write:
_read() = _rbits;
I thought you might have thought this was how you returned the function value.
Well i have done a little visual basic, but not much, i did more visual c++.
and i have made an arduino sketch thad did, for example:
boolean yn(int pin)
{
yn = digitalRead(pin);
}
Not one that compiled, right?
sketch_apr23c.cpp: In function 'boolean yn(int)':
sketch_apr23c:2: error: assignment of function 'boolean yn(int)'
sketch_apr23c:2: error: cannot convert 'int' to 'boolean ()(int)' in assignment
hmm, well i know it was something like that, mabey i used if statements or something, i don't know. it was a while ago. Well ill test the lib tomorrow...