Doubt working with multiple

2

I'm developing a Sketch and I need to use multiples of one, but I do not think I know how to work right with them. I have a FOR loop that goes from 1 to 72 and I need to count and go showing the messages on the screen. The problem is that you have a message that is being repeated because more than 1 number is a multiple of 3, how can I fix it?

OBS: By loop going to 72 is normal after displaying the last message, start all over again, then I will have 2 separate message blocks.

I need to do this:

1 ) A cada 1  byte  exibe no terminal ( BLOCO ! )
2 ) A cada 21 bytes exibe no terminal ( BLOCO 2 )
3 ) A cada 29 bytes exibe no terminal ( BLOCO 3 )
4 ) A cada 35 bytes exibe no terminal ( BLOCO 4 )
5 ) A cada 36 bytes exibe no terminal ( BLOCO 5 )

CODE:

  for(i = 1; i < 72; i ++)
  {

    if ((i % 1 == 0) && ((i) % 1 == 0))
    {
      Serial.println("BLOCO 1");
    }
    else if ((i % 21 == 0) && ((i) % 3 == 0))
    {
      Serial.println("BLOCO 2");
    }
    else if ((i % 29 == 0) && ((i) % 3 == 0))
    {
      Serial.println("BLOCO 3");
    }
    else if ((i % 35 == 0) && ((i) % 5 == 0))
    {
      Serial.println("BLOCO 4");
    }
    else if ((i % 36 == 0) && ((i) % 3 == 0))
    {
      Serial.println("BLOCO 5");
    }
}
    
asked by anonymous 26.04.2016 / 22:49

1 answer

1

If I understood your question correctly, you need to display messages in a block of bytes. Therefore, as follows, 71 messages will be printed exactly:

    for (int i = 1; i < 72; i++) {

        if (i % 21 == 0) {
            Serial.println("BLOCO 2");
            continue;
        }
        if (i % 29 == 0) {
            Serial.println("BLOCO 3");
            continue;
        }
        if (i % 35 == 0) {
            Serial.println("BLOCO 4");
            continue;
        }
        if (i % 36 == 0) {
            Serial.println("BLOCO 5");
            continue;
        }

        Serial.println("BLOCO 1");
    }
    
26.04.2016 / 23:43