我宣告了通過 8 通道 i2c Mux 運行的多個 OLED 顯示幕:
Adafruit_SSD1306 display1(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire2, OLED_RESET);
Adafruit_SSD1306 display2(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire2, OLED_RESET);
Adafruit_SSD1306 display3(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire2, OLED_RESET);
Adafruit_SSD1306 display4(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire2, OLED_RESET);
Adafruit_SSD1306 display5(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire2, OLED_RESET);
我希望能夠使用這樣的識別符號訪問這些:
display[0].print("etc");
display[1].print("etc");
display[2].print("etc");
所以我可以呼叫這樣的函式:
sendTitleDisplay(1);
void sendTitleDisplay(uint8_t id)
{
display[id].print("title example");
}
我將如何定義這些物件,以便我可以以這種陣列格式訪問它們?
uj5u.com熱心網友回復:
你可以像這樣初始化你的陣列:
Adafruit_SSD1306 display[]{
{SCREEN_WIDTH, SCREEN_HEIGHT, &Wire2, OLED_RESET},
{SCREEN_WIDTH, SCREEN_HEIGHT, &Wire2, OLED_RESET},
{SCREEN_WIDTH, SCREEN_HEIGHT, &Wire2, OLED_RESET},
{SCREEN_WIDTH, SCREEN_HEIGHT, &Wire2, OLED_RESET},
{SCREEN_WIDTH, SCREEN_HEIGHT, &Wire2, OLED_RESET},
};
這將為每個Adafruit_SSD1306實體使用第一個新的推薦建構式,clkDuring使用默認值400000UL和clkAfter使用默認值100000UL。
// NEW CONSTRUCTORS -- recommended for new projects
Adafruit_SSD1306(uint8_t w, uint8_t h, TwoWire *twi = &Wire,
int8_t rst_pin = -1, uint32_t clkDuring = 400000UL,
uint32_t clkAfter = 100000UL);
Adafruit_SSD1306(uint8_t w, uint8_t h, int8_t mosi_pin, int8_t sclk_pin,
int8_t dc_pin, int8_t rst_pin, int8_t cs_pin);
Adafruit_SSD1306(uint8_t w, uint8_t h, SPIClass *spi, int8_t dc_pin,
int8_t rst_pin, int8_t cs_pin, uint32_t bitrate = 8000000UL);
// DEPRECATED CONSTRUCTORS - for back compatibility, avoid in new projects
Adafruit_SSD1306(int8_t mosi_pin, int8_t sclk_pin, int8_t dc_pin,
int8_t rst_pin, int8_t cs_pin);
Adafruit_SSD1306(int8_t dc_pin, int8_t rst_pin, int8_t cs_pin);
Adafruit_SSD1306(int8_t rst_pin = -1);
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/457298.html
