-
Notifications
You must be signed in to change notification settings - Fork 64
/
seesaw_spectrum.h
70 lines (61 loc) · 2.64 KB
/
seesaw_spectrum.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
#ifndef _SEESAW_SPECTRUM_H
#define _SEESAW_SPECTRUM_H
#include "Adafruit_seesaw.h"
#include <Arduino.h>
/**************************************************************************/
/*!
@brief Class that stores state and functions for seesaw audio spectrum
interface
*/
/**************************************************************************/
class seesaw_Audio_Spectrum : public Adafruit_seesaw {
public:
/**************************************************************************/
/*!
@brief seesaw_Audio_Spectrum class constructor.
@param Wi TwoWire interface this works through.
*/
/**************************************************************************/
seesaw_Audio_Spectrum(TwoWire *Wi = NULL) : Adafruit_seesaw(Wi) {}
~seesaw_Audio_Spectrum() {}
/**************************************************************************/
/*!
@brief Begin communication with Seesaw audio spectrum device.
@param addr Optional i2c address where the device can be found.
Defaults to SEESAW_ADDRESS.
@param flow Optional flow control pin.
@return true on success, false on error.
*/
/**************************************************************************/
bool begin(uint8_t addr = SEESAW_ADDRESS, int8_t flow = -1) {
if (Adafruit_seesaw::begin(addr, flow)) {
memset(bins, 0, sizeof bins);
return true;
}
return false;
}
void getData(void); // Fetch latest audio spectrum data
void setRate(uint8_t value); // Set audio sampling rate 0-31
void setChannel(uint8_t value); // Set ADC input channel
uint8_t getRate(void); // Query current audio sampling rate 0-31
uint8_t getChannel(void); // Query current ADC channel
/**************************************************************************/
/*!
@brief Get value of individual spectrum bin, as determined during
most recent get_data() call.
@param idx Spectrum bin index (0-63) to query.
@return Level: 0 (silent) to 255 (loudest) for bin.
*/
/**************************************************************************/
uint8_t getLevel(uint8_t idx) const { return bins[idx < 64 ? idx : 63]; }
/**************************************************************************/
/*!
@brief Get pointer to spectrum bin buffer directly. Use with caution!
@return uint8_t base pointer to 64 spectrum bins.
*/
/**************************************************************************/
uint8_t *getBuffer(void) const { return (uint8_t *)bins; }
private:
uint8_t bins[64]; // Audio spectrum "bins"
};
#endif // end _SEESAW_SPECTRUM_H