Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
brewmanz opened this issue Oct 29, 2020 · 0 comments
Labels
type: imperfection Perceived defect in any part of project

Comments

@brewmanz
Copy link

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.

@brewmanz brewmanz changed the title with 'void pulse(int pin, int times)', it typically pulses times + 1, which is unexpected 11.ArduinoISP/ArduinoISP.ino: with 'void pulse(int pin, int times)', it typically pulses times + 1, which is unexpected Oct 29, 2020
@per1234 per1234 added the type: imperfection Perceived defect in any part of project label Oct 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: imperfection Perceived defect in any part of project
Projects
None yet
Development

No branches or pull requests

2 participants