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);
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.
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)).
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?