Skip to content

Commit 88ccac3

Browse files
authored
Update Tone.cpp
1 parent bab599c commit 88ccac3

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

cores/esp8266/Tone.cpp

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
/*
22
Tone.cpp
3-
3+
44
A Tone Generator Library for the ESP8266
5-
5+
66
Original Copyright (c) 2016 Ben Pirt. All rights reserved.
77
This file is part of the esp8266 core for Arduino environment.
8-
8+
99
This library is free software; you can redistribute it and/or
1010
modify it under the terms of the GNU Lesser General Public
1111
License as published by the Free Software Foundation; either
1212
version 2.1 of the License, or (at your option) any later version.
13-
13+
1414
This library is distributed in the hope that it will be useful,
1515
but WITHOUT ANY WARRANTY; without even the implied warranty of
1616
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1717
Lesser General Public License for more details.
18-
18+
1919
You should have received a copy of the GNU Lesser General Public
2020
License along with this library; if not, write to the Free Software
2121
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
@@ -34,7 +34,9 @@ static void _startTone(uint8_t _pin, uint32_t high, uint32_t low, uint32_t durat
3434
return;
3535
}
3636

37-
pinMode(_pin, OUTPUT);
37+
if (!(_toneMap & 1UL << _pin)) {
38+
pinMode(_pin, OUTPUT);
39+
}
3840

3941
high = std::max(high, (uint32_t)microsecondsToClockCycles(25)); // new 20KHz maximum tone frequency,
4042
low = std::max(low, (uint32_t)microsecondsToClockCycles(25)); // (25us high + 25us low period = 20KHz)
@@ -43,7 +45,7 @@ static void _startTone(uint8_t _pin, uint32_t high, uint32_t low, uint32_t durat
4345
duration += high + low - 1;
4446
duration -= duration % (high + low);
4547
if (startWaveformClockCycles(_pin, high, low, duration)) {
46-
_toneMap |= 1 << _pin;
48+
_toneMap |= 1UL << _pin;
4749
}
4850
}
4951

@@ -86,6 +88,6 @@ void noTone(uint8_t _pin) {
8688
return;
8789
}
8890
stopWaveform(_pin);
89-
_toneMap &= ~(1 << _pin);
91+
_toneMap &= ~(1UL << _pin);
9092
digitalWrite(_pin, 0);
9193
}

0 commit comments

Comments
 (0)