# Using an integer to blink an led?

I have a sketch counting up from 1 to 255 in increments of 10 and back down and I need to blink an led when that value is a multiple of 10. Is there a way to do this without using an if statement for each increment?

Counting in increments of 10?

Want to test if the value is a multiple of 10?

A) Never
B) Always

I misspoke in my first post. I meant that the led should light at each increment, not when it is a multiple of 10. I have no problem doing this with multiple if statements, but was wondering if there is an easier way to do this.

I misstated in my opening post. I need the led to blink when an increment is reached, not a multiple of 10

I was OK with the original requirement but now I am lost.

Can you give some examples of when the LED should blink based on your code ?

This loop counts up from 0 to 250 in increments of 10. When the value is 10, 20, 30 etc, I want an led to blink.

``````void loop()
{
int x = 10;
for (int i = 0; i > -1; i = i + x){
analogWrite(A14, i);
if (i == 250) x = -10;
if (i == 0) x = 10;
delay(100);
Serial.println(i);
}
``````

That is what you said originally

``````void setup()
{
Serial.begin(115200);
for (int myInteger = 1; myInteger < 101; myInteger++)
{
if (myInteger%10 == 0)
{
Serial.print(myInteger);
Serial.println(" is divisible by 10");
}
}
}

void loop()
{
}
``````

The modulus operator % gives you the remainder of a division. So if you take your number and take the modulus of 10 of it, the result will be zero every ten counts. Use an if statement to look at the result and turn the LED on or off accordingly.

Thanks very much Grumpy_Mike!

This loop counts up from 0 to 250 in increments of 10. When the value is 10, 20, 30 etc, I want an led to blink.

You failed to answer the question in reply #1. If you think about your "requirement" and the algorithm you are using, the answer will be either always or never, depending on the initial value.

Given that on every pass through the for loop the value either will be a multiple of 10, or will never be a multiple of 10, you will either always blink the LED or never blink it.

It isn't clear why you can't see that, or why you think you need extra code to test that the value is, or is not, a multiple of 10.