Go Down

### Topic: Functions (Read 776 times)previous topic - next topic

#### cecilz

##### May 08, 2007, 04:29 am
Hi.  I am trying to work around the inability of the Arduino to handle floating point reads/writes.  The following code gets a diagnostic of :
R cannot be used as a function.
code is:
int R(2);

long Vout = 0;
int Int1 = 0;
int Rnum = 0;
int Temp = 0;

R(Rnum)=(R(Rnum) * 10)+Temp;   //shift left & add new char

I'm new to C+ but it seems to me that these are just subscripted variables.

What gives?

Zach

#### mellis

#1
##### May 08, 2007, 06:05 am
Can you post your whole sketch?

The R(2) syntax means that you are calling the function called R, and passing it the argument 2.  What are you trying to do?

#### cecilz

#2
##### May 08, 2007, 07:19 am
This routine is to calculate the resulting voltage for an LM350T when the two resistor values are given.  The R() is not a function, but the representative values of the resistors in a 2 cel vector (array).

Since arrays are permitted, I am convused.  Thank you for your time and help.

Zach

int R(2);
int Rnum = 0;
int Temp = 0;
long Vout = 0;

void getRes ()
{
for(Rnum = 0;Rnum<2;Rnum++);  //Gets two resistor values
{
Serial.print("R");
Serial.print(Rnum,DEC);
Serial.print("= ");        //Request resistor #'Rnum' Value
while (Serial.available () == 0)
{
delay (2000);
}

while(Serial.available() > 0)
{
R(Rnum)=(R(Rnum) * 10)+Temp;//shift left & add new char
}
}
Serial.flush ();
}

void CalcVoltage ()
{
Vout = (1.25 * (1+R(2)/R(1))+R(2)*)100; // *100 keeps the 1st 2 deci places when
// converting to integer.
}

void DisplayVolts ()
{
Serial.print("Vout= ");
Serial.println(Vout,DEC);
}

void setup ()
{
Serial.begin(9600);
}

void loop ()
{
getRes ();
CalcVoltage ();
DisplayVolts ();
}

#### cecilz

#3
##### May 08, 2007, 07:39 am
Well, as usual, I am the problem..  thanks for you time.  The problem is that being new to C+ I wasn't subscripting with square brackets [], and so the system expected functions.  Naturally.  egg on face.

Oh well, thank you again.

Go Up

Please enter a valid email to subscribe