-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimerFreeTone.h
More file actions
66 lines (63 loc) · 2.93 KB
/
TimerFreeTone.h
File metadata and controls
66 lines (63 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// ---------------------------------------------------------------------------
// TimerFreeTone Library - v1.5 - 09/12/2016
//
// AUTHOR/LICENSE:
// Created by Tim Eckel - teckel@leethost.com
// Copyright 2016 License: GNU GPL v3 http://www.gnu.org/licenses/gpl-3.0.html
//
// LINKS:
// Project home: https://bitbucket.org/teckel12/arduino-timer-free-tone
// Blog: http://forum.arduino.cc/index.php?topic=235774.0
//
// DISCLAIMER:
// This software is furnished "as is", without technical support, and with no
// warranty, express or implied, as to its usefulness for any purpose.
//
// PURPOSE:
// Doesn't use timers which frees up conflicts with other libraries. Compatible
// with all ATmega, ATtiny and ARM-based microcontrollers. About 1,500 bytes
// smaller binary sketch size than the standard tone library. Exclusive use of
// port registers for AVR-based microcontrollers for fastest and smallest code.
// Close to a plug-in replacement for the standard Tone library.
//
// SYNTAX:
// TimerFreeTone( pin, frequency, duration [, volume ] ) - Play a note on pin at frequency in Hz for duration in milliseconds.
// Parameters:
// * pin - Pin speaker is wired to (other wire to ground, be sure to add an inline 100 ohm resistor).
// * frequency - Play the specified frequency (should work fairly well in the 100 to 15000 Hz range).
// * duration - Set the duration to play in milliseconds. Range: 0 to 65535 (65.5 seconds).
// * volume - Optionally set the tone volume level (from 1 to 10), defaults to full volume (10).
//
// HISTORY:
// 09/12/2016 v1.5 - Fixed problem with latest release of the Arduino IDE which
// caused the library to totally stop functioning. Adjusted note duration to
// not fail on timer rollover. Now delays for note duration when frequency or
// volume are zero.
//
// 08/05/2016 v1.4 - Added optional volume parameter.
//
// 07/23/2016 v1.3 - Fixed problem with long tone play durations. Changed the
// way the note duration is calculated from a suggestion by Paul Stoffregen
// (http://www.pjrc.com/teensy/).
//
// 01/14/2015 v1.2 - Calculates duration differently for higher tone accuracy
// and smaller code size.
//
// 04/30/2014 v1.1 - Automatically sets mode of pin to OUTPUT as does the
// standard Tone library. Sets pinOutput variable to volatile to work with
// certain microcontrollers. Removed overhead parameter and calculation, fairly
// accurate anyway at audible frequencies. Even smaller binary sketch size.
//
// 04/25/2014 v1.0 - Initial release.
//
// ---------------------------------------------------------------------------
#ifndef TimerFreeTone_h
#define TimerFreeTone_h
#if defined(ARDUINO) && ARDUINO >= 100
#include <Arduino.h>
#else
#include <WProgram.h>
#include <pins_arduino.h>
#endif
void TimerFreeTone(uint8_t pin, unsigned long frequency, unsigned int duration, uint8_t volume = 10);
#endif