```cpp
/*#include "Adafruit_GFX.h"
#include <Adafruit_GrayOLED.h>
#include <Adafruit_SPITFT.h>
#include <Adafruit_SPITFT_Macros.h>
#include <gfxfont.h>
*/
#include <Adafruit_SSD1306.h>
#include <spi.h>
#include <Wire.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
// The pins for I2C are defined by the Wire-library.
// On an arduino UNO: A4(SDA), A5(SCL)
// On an arduino MEGA 2560: 20(SDA), 21(SCL)
// On an arduino LEONARDO: 2(SDA), 3(SCL), ...
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3c ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display1(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
Adafruit_SSD1306 display2(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
Adafruit_SSD1306 display3(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
Adafruit_SSD1306 display4(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
Adafruit_SSD1306 display5(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
/*
Tell DCS-BIOS to use a serial connection and use the default Arduino Serial
library. This will work on the vast majority of Arduino-compatible boards,
but you can get corrupted data if you have too many or too slow outputs
(e.g. when you have multiple character displays), because the receive
buffer can fill up if the sketch spends too much time updating them.
If you can, use the IRQ Serial connection instead.
*/
#define DCSBIOS_DEFAULT_SERIAL
#define ENABLE_PULLUPS
#include "DcsBios.h"
/*typedef DcsBios::RotaryEncoderT<POLL_EVERY_TIME, DcsBios::FOUR_STEPS_PER_DETENT> FourStepRotaryEncoder; // A custom rotary encoder with four quadrature steps per physical detent.
FourStepRotaryEncoder tacan1("TACAN_1", "DEC", "INC", 0, 1);*/
void TCA9548A (uint8_t bus){
Wire.beginTransmission(0x70);
Wire.write(1<<bus);
Wire.endTransmission();
}
// cue
void onUfcOptionCueing1Change(char* newValue) {
TCA9548A(0);
display1.setCursor(0, 6);
display1.print (newValue);
display1.display();
}
DcsBios::StringBuffer<1> ufcOptionCueing1Buffer(FA_18C_hornet_UFC_OPTION_CUEING_1, onUfcOptionCueing1Change);
void onUfcOptionCueing2Change(char* newValue) {
TCA9548A(1);
display2.setCursor(0, 6);
display2.print (newValue);
display2.display();
}
DcsBios::StringBuffer<1> ufcOptionCueing2Buffer(FA_18C_hornet_UFC_OPTION_CUEING_2, onUfcOptionCueing2Change);
void onUfcOptionCueing3Change(char* newValue) {
TCA9548A(2);
display3.setCursor(0, 6);
display3.print (newValue);
display3.display();
}
DcsBios::StringBuffer<1> ufcOptionCueing3Buffer(FA_18C_hornet_UFC_OPTION_CUEING_3, onUfcOptionCueing3Change);
void onUfcOptionCueing4Change(char* newValue) {
TCA9548A(3);
display4.setCursor(0, 6);
display4.print (newValue);
display4.display();
}
DcsBios::StringBuffer<1> ufcOptionCueing4Buffer(FA_18C_hornet_UFC_OPTION_CUEING_4, onUfcOptionCueing4Change);
void onUfcOptionCueing5Change(char* newValue) {
TCA9548A(4);
display5.setCursor(0, 6);
display5.print (newValue);
display5.display();
}
DcsBios::StringBuffer<1> ufcOptionCueing5Buffer(FA_18C_hornet_UFC_OPTION_CUEING_5, onUfcOptionCueing5Change);
// end of cueing
//-------------------------------------------
//option
void onUfcOptionDisplay1Change(char* newValu6e) {
TCA9548A(0);
display1.setCursor(30, 6);
display1.print (newValu6e);
display1.display();
}
DcsBios::StringBuffer<4> ufcOptionDisplay1Buffer(FA_18C_hornet_UFC_OPTION_DISPLAY_1, onUfcOptionDisplay1Change);
void onUfcOptionDisplay2Change(char* newValu6e) {
TCA9548A(1);
display2.setCursor(30, 6);
display2.print (newValu6e);
display2.display();
}
DcsBios::StringBuffer<4> ufcOptionDisplay2Buffer(FA_18C_hornet_UFC_OPTION_DISPLAY_2, onUfcOptionDisplay2Change);
void onUfcOptionDisplay3Change(char* newValu6e) {
TCA9548A(2);
display3.setCursor(30, 6);
display3.print (newValu6e);
display3.display();
}
DcsBios::StringBuffer<4> ufcOptionDisplay3Buffer(FA_18C_hornet_UFC_OPTION_DISPLAY_3, onUfcOptionDisplay3Change);
void onUfcOptionDisplay4Change(char* newValu6e) {
TCA9548A(3);
display4.setCursor(30, 6);
display4.print (newValu6e);
display4.display();
}
DcsBios::StringBuffer<4> ufcOptionDisplay4Buffer(FA_18C_hornet_UFC_OPTION_DISPLAY_4, onUfcOptionDisplay4Change);
void onUfcOptionDisplay5Change(char* newValu6e) {
TCA9548A(4);
display5.setCursor(30, 6);
display5.print (newValu6e);
display5.display();
}
DcsBios::StringBuffer<4> ufcOptionDisplay5Buffer(FA_18C_hornet_UFC_OPTION_DISPLAY_5, onUfcOptionDisplay5Change);
void setup() {
Serial.begin (9600);
Wire.begin();
TCA9548A(0);
display1.clearDisplay();
display1.setTextSize(4);
display1.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS);
display1.setTextColor(WHITE, BLACK);
TCA9548A(1);
display2.clearDisplay();
display2.setTextSize(4);
display2.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS);
display2.setTextColor(WHITE, BLACK);
TCA9548A(2);
display3.clearDisplay();
display3.setTextSize(4);
display3.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS);
display3.setTextColor(WHITE, BLACK);
TCA9548A(3);
display4.clearDisplay();
display4.setTextSize(4);
display4.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS);
display4.setTextColor(WHITE, BLACK);
TCA9548A(4);
display5.clearDisplay();
display5.setTextSize(4);
display5.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS);
display5.setTextColor(WHITE, BLACK);
DcsBios::setup();
}
void loop(){
DcsBios::loop();
}
Hi.
I have 5 SSD1306 displays connected to an TCA9548A and that to the arduino nano clone.
My wiring is correct because if i upload a copy of this code but with only one Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); instead of 5 and i change everything bellow to display.(whatever setCursor, print, etc.) all screens turn on but what i'm passing to them from the game (DCS) is repeated or distributed by several screens.
The way i have it in this example it usually only turns on 1 display and many times it only shows garbled pixels.
note: all displays are also connected grd-grd and vin-5v