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

Updated Tone.cpp to allow specifying pin state on noTone #532

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cores/arduino/Arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout = 10

void tone(uint8_t _pin, unsigned int frequency, unsigned long duration = 0);
void noTone(uint8_t _pin);
void noTone(uint8_t _pin, bool _exit_state);

// WMath prototypes
long random(long);
Expand Down
17 changes: 17 additions & 0 deletions cores/arduino/Tone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,23 @@ void noTone(uint8_t _pin)
digitalWrite(_pin, 0);
}


void noTone(uint8_t _pin, bool _exit_state)
{
int8_t _timer = -1;

for (int i = 0; i < AVAILABLE_TONE_PINS; i++) {
if (tone_pins[i] == _pin) {
_timer = pgm_read_byte(tone_pin_to_timer_PGM + i);
tone_pins[i] = 255;
break;
}
}

disableTimer(_timer);
digitalWrite(_pin, _exit_state);
}

#ifdef USE_TIMER0
ISR(TIMER0_COMPA_vect)
{
Expand Down