Hi everybody,
Newbie here. How can I make to do something when the program loops 15 times.My program is I am calculating the data, when the data is 15 times runned, i want to reset to 0.
void loop()
{
i++;
if(15==i)
{
i=0;
}
}
or
void loop()
{
i = 0
while(i < 15)
{
stuff();
++i;
}
}
or
void loop()
{
for(byte i = 0; i < 15; ++i)
{
stuff();
}
}
ah....sry brother...I cannot understand...let's say if this is my program...How can i Stop at 15th loop(making datastore 0)?I mean I want to continue the loop but I want to reset the datastore to 0.
float KWH;
KWH=(float) pow/1000/60;
Serial.print("Total energy usage for 1 min=");
Serial.println(KWH,2);
datastore= datastore + KWH;
//float finaldata=datastore+KWH;
Serial.print("DATA=");
Serial.println(datastore,2);
i = 0
while(i < 15)
{
stuff();
i++;
}
heres your problem, its going to loop 15 times in a matter of milliseconds, if not microseconds... more info is needed
It's going to loop in a microseconds and it will continue looping..but every 15 times, the data is reset to 0
void loop()
{
for(byte i = 0; i < 15; ++i)
{
float KWH;
KWH=(float) pow/1000/60;
Serial.print("Total energy usage for 1 min=");
Serial.println(KWH,2);
datastore= datastore + KWH;
//float finaldata=datastore+KWH;
Serial.print("DATA=");
Serial.println(datastore,2);
}
datastore = 0;
}
its a loop in a loop, above using a for loop (which is what I would do) will go from 0-14 (15 times) exit and start the main loop over again, which starts the for loop again going from 0-14
float KWH;
KWH=(float) pow/1000/60;
Serial.print("Total energy usage for 1 min=");
Serial.println(KWH,2);
datastore= datastore + KWH;
//float finaldata=datastore+KWH;
Serial.print("DATA=");
Serial.println(datastore,2);
if(15==i)
{
datastore=0;
i=0;
}
i++;
declare i global
thank you brothers....It works