Skip to content

11.ArduinoISP/ArduinoISP.ino: with 'void pulse(int pin, int times)', it typically pulses times + 1, which is unexpected  #22

Open
@brewmanz

Description

@brewmanz

The following code typically loops one more time than times e.g. with 0, it loops once, with 1, it loops twice.

#define PTIME 30
void pulse(int pin, int times) {
  do {
    digitalWrite(pin, HIGH);
    delay(PTIME);
    digitalWrite(pin, LOW);
    delay(PTIME);
  } while (times--);
}

ADDITIONAL SUGGESTION#1: Decide whether it should loop 0 times or once, when times is set to 0; looping almost forever is probably not desired.
ADDITIONAL SUGGESTION#2: Add optional additional parameter int duration that defaults to PTIME or 30.

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: imperfectionPerceived defect in any part of project

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy