Arduino Uno Cycle Counter

Hello,

I have set up a certain code to make a linear actuator inflate and retract a balloon.

However, now I need to create a cycle counter to count 20,000 cycles of the balloon inflating and retracting. Each period is 15 seconds long. I have the Arduino Uno, but I do not know how to implement a timer that can be displayed on the code while the project is running.

Help please!!

This is the code that I have to run the linear actuator:

#include <Servo.h>

#include <Servo.h>
int servoPin = 9;
Servo servo;
int angle = 0; // servo position in degrees
void setup ()
{
servo.attach(servoPin);
}
void loop()
{
// scan from 0 to desired inflated degrees

for (angle = 0; angle < 360; angle++)
{
servo.write(angle);
delay(9);
}
// now scan back from desired inflated degrees to desired retracted degrees
for (angle = 360; angle > -200; angle–)
{
servo.write(angle);
delay(20);
}
}

but I do not know how to implement a timer that can be displayed on the code while the project is running.

Why do you need a timer to count actions? Maybe you need an ice cream cone, instead.

You are running the "servo" from 0 to 360 and then from 360 to -200. Next time around, the servo is going to jump from -200 to 1. Doesn't make sense to me.

int counter = 0;

and add one to it each time you inflate?

How do you detect "broken" balloons?

Thank you MarkT.

MarkT:

int counter = 0;

and add one to it each time you inflate?

I tried that, but what would an example of that be? I put the following code, but it did not work. Also, how would the number of cycles be shown on the screen??:

void loop()
{
// scan from 0 to desired inflated degrees

for (angle = 0; angle < 360; angle++)
{
servo.write(angle);
delay(9);
}

{
for (counter= 0; counter <20000; counter++)
servo.write(counter);
}

// now scan back from desired inflated degrees to desired retracted degrees
for (angle = 360; angle > -200; angle–)
{
servo.write(angle);
delay(20);
}
}

I put the following code, but it did not work.

Suppose that you got smart and created a function to inflate and deflate the balloon. What would that function look like?

Suppose that you called that function from loop(). What would that call look like?

Suppose you wanted to call that function only 20000 times. How would you do that, given that loop() is called in an endless loop?