program error using do while

can anyone please tell me the problem in this code its showing the exit staTus 1
and error on the line with float vary.
also, its telling to add a ; before that line.

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

}

void loop()
{
long int to=millis();
float v1= (5.0/1023.0)*analogRead(A5);
float i1= (5.0/1023.0)*analogRead(A4);
float v2= (5.0/1023.0)*analogRead(A3);
float i2= (5.0/1023.0)*analogRead(A2);

delay(11000);
do
{
float var =v1/i1;
Serial.print('\n');
Serial.print("time:\n"));
Serial.print(to);
Serial.print('\n');
Serial.print("v1:\n");
Serial.print(v1);
Serial.print('\n');
Serial.print("i1:\n");
Serial.print(i1);
Serial.print('\n');
Serial.print("var1:\n");
Serial.print(var1);
}
while(to=11000);

delay(3000)
do
{
float vari =v2/i2;
Serial.print('\n');
Serial.print("time:\n"));
Serial.print(to);
Serial.print('\n');
Serial.print("v2:\n");
Serial.print(v2);
Serial.print('\n');
Serial.print("i2:\n");
Serial.print(i2);
Serial.print('\n');
Serial.print("var2:\n");
Serial.print(var2);
}
while(to>11000);

float vary =var-vari;
Serial.print('\n');
Serial.print("difference\n");
Serial.print(vary);
delay(30000);
}

You have much more serious problems in your code than the one you asked about, apart from the fact that you also never formatted or posted it correctly. When millis() reaches 11000, you get stuck in an endless while loop because variable 'to' never changes inside the loop. There are probably more mistakes. Please explain what the program is trying to do, and read the sticky posts at the top of the forum to learn how to post code.

devilmoriarty:
while(to=11000);

= means assignment, == checks for equality.

devilmoriarty:
delay(3000)

As usual, the compiler is right, and you missed a semicolon.

devilmoriarty:
long int to=millis();

Millis returns an unsigned long. Use auto to = millis() or unsigned long to = millis() instead.

Your method of keeping time is flawed as well, the "to" variable is never updated inside of the loop, so the loop can never exit. Also never check for equality when using millis, use greater than. Never add times together, only subtract them (e.g. while(millis() - prevTime < duration)).

Pieter

i want to create a program which will record a sensor data over a time delay. that is i want v1 and i1 to be recorded after 11 secs and v2 and i2 after 3 more seconds. then i want to find the data differnce= var1- var2;
the thing is var1=v1/i1 and var2=v2/i2
now the thing is i jave to change the simulation data that is v1 i1 v2 and i2 which i am simulating by using 2 potentiometers. the problem i am encountering is that the difeernce is coming 0 everytime. maybe because the previous values of v1 and i1 are changing. how can i stop that i even tried taking two differnt analog input buttons for the other!

analogRead Reads the value from an analogue pin and stores it in a variable. That’s it. If the analogue value on the pin changes, the variable does not automatically get updated. To update the variable you need to call analogRead again.

Similarly with variable to and function millis() which retrieves the current time in milliseconds.

Q: Where are you calling analogRead in your do while loops?

Q: Where are you calling millis() in your do while loops?

would this following work for you?

in order to avoid the inability to print floating pt values, values are scaled by 1000: mV, mA and mOhm. (analog inputs are floating)

results

sample:
dump:
     0:   1900   1764   4092   4092     1077   1000      77
     1:   2716   2132   4092   4092     1273   1000     273
     2:   2968   2340   4092   4092     1268   1000     268
     3:   3080   2472   4092   4092     1245   1000     245
     4:   3136   2560   4092   4092     1225   1000     225
     5:   3172   2624   4092   4092     1208   1000     208
     6:   3192   2664   4092   4092     1198   1000     198
     7:   3200   2692   4092   4092     1188   1000     188
     8:   3208   2712   4092   4092     1182   1000     182
     9:   3216   2728   4092   4092     1178   1000     178
    10:   3220   2740   4092   4092     1175   1000     175
    11:   3228   2748   4092   4092     1174   1000     174
    12:   3228   2760   4092   4092     1169   1000     169
#define N  13
int v1 [N];
int i1 [N];
int v2 [N];
int i2 [N];

#define C   (5000 / 1024)
#define K   1000.0

// ---------------------------------------------------------
void sample (void) {
    Serial.println ("sample:");

    unsigned long msec;
    unsigned long msecLst = millis();

    for (unsigned n = 0; n < N; n++)  {

        v1 [n] = C * analogRead(A5);
        i1 [n] = C * analogRead(A4);

        v2 [n] = C * analogRead(A3);
        i2 [n] = C * analogRead(A2);

#define SamplePeriod  500
        while ((msec = millis()) - msecLst < SamplePeriod)
            ;
        msecLst = msec;
    }
}

// ---------------------------------------------------------
void dump (void) {
    char s [80];

    Serial.println ("dump:");

    for (unsigned n = 0; n < N; n++)  {
        int r1 = K * v1 [n] / i1 [n];
        int r2 = K * v2 [n] / i2 [n];
        sprintf (s, "  %4d: %6d %6d %6d %6d   %6d %6d  %6d",
            n, v1 [n], i1 [n], v2 [n], i2 [n],  r1, r2, r1 - r2 );
        Serial.println (s);
    }
}

// ---------------------------------------------------------
void setup()
{
    Serial.begin(115200);

    sample ();
    dump ();
}

void loop()
{
#if 0
    long int to=millis();
    float v1= (5.0/1023.0)*analogRead(A5);
    float i1= (5.0/1023.0)*analogRead(A4);
    float v2= (5.0/1023.0)*analogRead(A3);
    float i2= (5.0/1023.0)*analogRead(A2);
    delay(11000);
    do
    {
        float var =v1/i1;
        Serial.print('\n');
        Serial.print("time:\n"));
        Serial.print(to);
        Serial.print('\n');
        Serial.print("v1:\n");
        Serial.print(v1);
        Serial.print('\n');
        Serial.print("i1:\n");
        Serial.print(i1);
        Serial.print('\n');
        Serial.print("var1:\n");
        Serial.print(var1);
    }

    while(to=11000);
    delay(3000)
    do
    {
        float vari =v2/i2;
        Serial.print('\n');
        Serial.print("time:\n"));
        Serial.print(to);
        Serial.print('\n');
        Serial.print("v2:\n");
        Serial.print(v2);
        Serial.print('\n');
        Serial.print("i2:\n");
        Serial.print(i2);
        Serial.print('\n');
        Serial.print("var2:\n");
        Serial.print(var2);
    }

    while(to>11000);
    float vary =var-vari;
    Serial.print('\n');
    Serial.print("difference\n");
    Serial.print(vary);
    delay(30000);
#endif
}