-
Notifications
You must be signed in to change notification settings - Fork 6
/
SineWave.h
46 lines (39 loc) · 1.46 KB
/
SineWave.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
/*
* SineWave.h - Arduino library for creating a sine wave on the fly.
* Created by C. Masenas, November 4, 2015. [email protected]
*
* This is free software. You can redistribute it and/or modify it under
* the terms of Creative Commons Attribution 3.0 United States License.
* To view a copy of this license, visit http://creativecommons.org/licenses/by/3.0/us/
* or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.
*
* Attribution must be given to the author for use of the sine generation algorithm.
* That's all I ask.
*/
#ifndef SineWave_h
#define SineWave_h
#include <TimerOne.h>
#define OUTPIN 9
class SineWave{
private:
const float pi = 3.14159 ;
const float A = 490 ;
int _pin = OUTPIN ;
float _T = 60/1000000.0 ;
float c1, c1b, c0;
volatile float a[3], b[3] ;
public:
void setInterval(float interval);
void setPin(int pin);
void playTone(float freq, int duration);
void playTone(float freq);
void playTone2(float freq1, float freq2, int duration);
void playTone2(float freq1, float freq2);
void playToneDecay(float freq, float tau); // play a tone with decaying amplitude of time constant tau
void stopTone(void);
void compute(void); // computes a sine tone
void compute2(void); // computes two tones simultaneously
void compute_decay(void); // computes a decaying sinewave
};
extern SineWave sw;
#endif