Skip to content

Commit 814c53e

Browse files
add MultiPlexer_TCA9548A
1 parent 4b1be4b commit 814c53e

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
MultiPlexer_TCA9548A.h - Control TCA9548A I2C multiplexer.
3+
*/
4+
5+
#include "MultiPlexer_TCA9548A.h"
6+
7+
MultiPlexer_TCA9548A::MultiPlexer_TCA9548A(int i2c_addr) {
8+
_mux = new TCA9548A(i2c_addr);
9+
}
10+
11+
void MultiPlexer_TCA9548A::begin() {
12+
_mux->begin(Wire); // TwoWire instance can be passed here as 3rd argument
13+
_mux->closeAll(); // Set a base state which we know (also the default state on power on)
14+
changeBus(0); // tell the TCA9548A we want to use I2C bus number zero (to talk to the OLED)
15+
}
16+
17+
void MultiPlexer_TCA9548A::changeBus(uint8_t bus_nr) {
18+
_mux->openChannel(bus_nr);
19+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
MultiPlexer_TCA9548A.h - Control TCA9548A I2C multiplexer.
3+
*/
4+
#ifndef MultiPlexer_TCA9548A_h
5+
#define MultiPlexer_TCA9548A_h
6+
7+
#include <Arduino.h>
8+
#include <Wire.h>
9+
#include <TCA9548A.h>
10+
11+
class MultiPlexer_TCA9548A
12+
{
13+
public:
14+
MultiPlexer_TCA9548A(int i2c_addr = 0x70);
15+
void begin();
16+
void changeBus(uint8_t bus_nr);
17+
18+
private:
19+
TCA9548A* _mux;
20+
};
21+
22+
#endif

0 commit comments

Comments
 (0)