Skip to content

Commit 380f045

Browse files
Updated Tone.cpp to allow specifying pin state on noTone
1 parent eabd762 commit 380f045

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

cores/arduino/Arduino.h

+1
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout = 10
246246

247247
void tone(uint8_t _pin, unsigned int frequency, unsigned long duration = 0);
248248
void noTone(uint8_t _pin);
249+
void noTone(uint8_t _pin, bool _exit_state);
249250

250251
// WMath prototypes
251252
long random(long);

cores/arduino/Tone.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,23 @@ void noTone(uint8_t _pin)
494494
digitalWrite(_pin, 0);
495495
}
496496

497+
498+
void noTone(uint8_t _pin, bool _exit_state)
499+
{
500+
int8_t _timer = -1;
501+
502+
for (int i = 0; i < AVAILABLE_TONE_PINS; i++) {
503+
if (tone_pins[i] == _pin) {
504+
_timer = pgm_read_byte(tone_pin_to_timer_PGM + i);
505+
tone_pins[i] = 255;
506+
break;
507+
}
508+
}
509+
510+
disableTimer(_timer);
511+
digitalWrite(_pin, _exit_state);
512+
}
513+
497514
#ifdef USE_TIMER0
498515
ISR(TIMER0_COMPA_vect)
499516
{

0 commit comments

Comments
 (0)