24 #if !defined(BOARD_ATTINY) 25 #if defined (__AVR_ATmega32U4__) \ 26 || defined(__AVR_ATmega640__) \ 27 || defined(__AVR_ATmega1280__) \ 28 || defined(__AVR_ATmega1281__) \ 29 || defined(__AVR_ATmega2560__) \ 30 || defined(__AVR_ATmega2561__) 35 #elif defined(__AVR_ATmega1284P__) \ 36 || defined(__AVR_ATmega644__) \ 37 || defined(__AVR_ATmega644P__) 42 #elif defined(__AVR_ATmega256RFR2__) 54 uint32_t Tone::s_expires;
56 200, 100, 67, 50, 40, 33, 29, 22, 11, 2
67 Tone::play(uint16_t freq, uint8_t volume, uint16_t duration,
bool background)
70 if (
UNLIKELY((freq == 0) || (volume == 0))) {
80 uint8_t prescaler = _BV(CS10);
81 uint32_t top = (F_CPU / freq / 2) - 1;
83 prescaler = _BV(CS12);
84 top = (top / 256) - 1;
88 uint16_t duty = top / pgm_read_byte(&s_map[volume - 1]);
91 if ((duration > 0) && background) {
96 if (TCNT1 > top) TCNT1 = top;
97 TCCR1B = (_BV(WGM13) | prescaler);
100 TCCR1A = (_BV(COM1A1) | _BV(COM1B1) | _BV(COM1B0));
103 if ((duration == 0) || background)
return;
117 PORT &= ~(_BV(PIN1) | _BV(PIN2));
const uint8_t Tone::s_map[] __PROGMEM
static void timer1_disable()
static void play(uint16_t freq, uint8_t volume=VOLUME_MAX/2, uint16_t duration=0, bool background=false)
static const uint8_t VOLUME_MAX
void(* delay)(uint32_t ms)
friend void TIMER1_COMPA_vect(void)
static void timer1_enable()