0

I expected the LED on ld1 (pin 7) to flash with a period of D1 (300) milliseconds. Similarly for ld2 (pin 8) with a period of D2 / 1000ms.

int ld1 = 7,   ld2 = 8;      /// led out put 
int D1  = 300, D2  = 1000;   /// times i need to delay 
bool on = 0,   tw  = 0; 

void setup()
{
    pinMode( ld1, OUTPUT );
    pinMode( ld2, OUTPUT );
}

void loop()
{
    int x = millis();

    if (x % D1 == 0 && x >= D1)
    {
        digitalWrite( ld1, on );
        on = !on;
    }

    if (x % D2 == 0 && x >= D2)
    {
        digitalWrite( ld2, tw );
        tw = !tw;
    } 
}
  • 2
    it is not possible to help you... you did not say what you expected – jsotola Jun 30 at 23:29
  • Is your wiring correct? The code looks OK (apart from the indentation) - the only worry is some new code causing delays, so millis() might skip some time-stamps, not giving you clean increments by 1ms. Especially if you're writing to serial etc. – Kingsley Jul 1 at 3:29
  • Please confirm this statement added to the question is correct, so that your question can be re-opened: "I expected the LED on ld1 (pin 7) to flash with a period of D1 (300) milliseconds. Similarly for ld2 (pin 8) with a period of D2 / 1000ms." – VE7JRO Jul 2 at 19:49