forked from bhagman/Tone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTone.h
75 lines (66 loc) · 1.77 KB
/
Tone.h
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
67
68
69
70
71
72
73
74
/*
|| @author Brett Hagman <[email protected]>
|| @contribution Fotis Papadopoulos <[email protected]>
|| @url http://wiring.org.co/
|| @url http://roguerobotics.com/
||
|| @description
|| | A Software Digital Square Wave Tone Generation Library
|| |
|| | Written by Brett Hagman
|| | http://www.roguerobotics.com/
|| |
|| | This is a Wiring Framework (Arduino) library to produce square-wave
|| | tones on an arbitrary pin.
|| |
|| | You can make multiple instances of the Tone object, to create tones on
|| | different pins.
|| |
|| | The number of tones that can be generated at the same time is limited
|| | by the number of hardware timers available on the hardware.
|| | (e.g. ATmega328 has 3 available timers, and the ATmega1280 has 6 timers)
|| |
|| | A simplified (single tone) version of this library has been included
|| | in the Wiring Framework since Wiring 0025 and in the Arduino distribution
|| | since Arduino 0018.
|| |
|| #
||
|| @license Please see the accompanying LICENSE.txt file for this project.
||
|| @name Software PWM Library
|| @type Library
|| @target Atmel AVR 8 Bit
||
|| @version 1.0.0
||
*/
#ifndef _Tone_h
#define _Tone_h
#ifndef TONE_COUNT_POSITIVE_EDGE
#ifndef TONE_COUNT_NEGATIVE_EDGE
#define TONE_COUNT_POSITIVE_EDGE
#endif
#endif
#include <stdint.h>
/*
|| Definitions
*/
int digitalReadOutputPin(uint8_t pin);
class Tone
{
public:
void begin(uint8_t tonePin);
bool isPlaying();
void play(uint16_t frequency, uint32_t duration = 0);
void playNPulses(uint16_t frequency, uint32_t pulses);
uint32_t getCount();
void resetCounter();
void stop();
private:
static uint8_t _tone_pin_count;
uint8_t _pin;
int8_t _timer;
};
#endif