Go Down

Topic: Looping 15 times (Read 489 times) previous topic - next topic

Jaay

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.

Cybernetician

Code: [Select]

void loop()
{
i++;
if(15==i)
{

    i=0;
}
}
From Idea To Invention

Osgeld

#2
Dec 04, 2012, 04:36 am Last Edit: Dec 04, 2012, 04:38 am by Osgeld Reason: 1
or
Code: [Select]

void loop()
{
   i = 0
   while(i < 15)
   {
       stuff();
        ++i;
   }
}


or

Code: [Select]
void loop()
{
   for(byte i = 0; i < 15; ++i)
   {
        stuff();
   }
}


Jaay

#3
Dec 04, 2012, 04:37 am Last Edit: Dec 04, 2012, 04:39 am by Jaay Reason: 1
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.
Code: [Select]
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);

Cybernetician

Code: [Select]

i = 0
   while(i < 15)
   {
       stuff();
       i++;
   }
From Idea To Invention

Go Up