forked from ajfisher/arduino-analog-multiplexer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanalogmuxdemux.h
63 lines (51 loc) · 2.29 KB
/
analogmuxdemux.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
#ifndef AnalogMuxDeMux_h
#define AnalogMuxDeMux_h
#include "Arduino.h"
#define AMDM_MS0 4
#define AMDM_MS1 3
#define AMDM_MS2 2
#define AMDM_SS0 7
#define AMDM_SS1 6
#define AMDM_SS2 5
class AnalogMux
{
public:
AnalogMux(uint8_t MS0, uint8_t MS1, uint8_t MS2, uint8_t readpin);
AnalogMux(uint8_t MS0, uint8_t MS1, uint8_t MS2, uint8_t SS0, uint8_t SS1, uint8_t SS2, uint8_t readpin);
AnalogMux(uint8_t readpin);
uint16_t AnalogRead(uint8_t pin);
uint16_t AnalogRead();
void SelectPin(uint8_t pin);
private:
void SetupMaster(uint8_t MS0, uint8_t MS1, uint8_t MS2, uint8_t readpin);
uint8_t _readpin; // which input pin is being used by the arduino to read state
uint8_t _MS0; // MSB selector for the master controller
uint8_t _MS1; // Centre bit selector for the master controller
uint8_t _MS2; // LSB selector for the master controller
uint8_t _SS0; // MSB selector for the slave controller
uint8_t _SS1; // Centre bit selector for the slave controller
uint8_t _SS2; // LSB selector for the slave controller
uint8_t _currentPin; // which pin on the multiplexer are we looking at.
bool _ms; // are we a master slave arrangement
};
class AnalogDeMux
{
public:
AnalogDeMux(uint8_t MS0, uint8_t MS1, uint8_t MS2, uint8_t writepin);
AnalogDeMux(uint8_t MS0, uint8_t MS1, uint8_t MS2, uint8_t SS0, uint8_t SS1, uint8_t SS2, uint8_t writepin);
AnalogDeMux(uint8_t writepin);
void AnalogWrite(uint8_t value);
void AnalogWrite(uint8_t wpin, uint8_t value);
void SelectPin(uint8_t pin);
private:
uint8_t _writepin; // which input pin is being used by the arduino to write state
uint8_t _MS0; // MSB selector for the master controller
uint8_t _MS1; // Centre bit selector for the master controller
uint8_t _MS2; // LSB selector for the master controller
uint8_t _SS0; // MSB selector for the slave controller
uint8_t _SS1; // Centre bit selector for the slave controller
uint8_t _SS2; // LSB selector for the slave controller
uint8_t _currentPin; // which pin on the multiplexer are we looking at.
};
void WriteSelectionPins(uint8_t S0, uint8_t S1, uint8_t S2, uint8_t pin);
#endif