Created
January 7, 2019 04:16
-
-
Save alexdmejias/9942daa7971a8f2cbf571c3761859e24 to your computer and use it in GitHub Desktop.
multiple i2c SSD1306 screens using u8x8. Display an increasing number on all of the screens
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
HelloWorld.ino | |
"Hello World" version for U8x8 API | |
Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/) | |
Copyright (c) 2016, [email protected] | |
All rights reserved. | |
Redistribution and use in source and binary forms, with or without modification, | |
are permitted provided that the following conditions are met: | |
* Redistributions of source code must retain the above copyright notice, this list | |
of conditions and the following disclaimer. | |
* Redistributions in binary form must reproduce the above copyright notice, this | |
list of conditions and the following disclaimer in the documentation and/or other | |
materials provided with the distribution. | |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND | |
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, | |
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR | |
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | |
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | |
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | |
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
*/ | |
#include <Arduino.h> | |
#include <U8x8lib.h> | |
#include <Wire.h> | |
#ifdef U8X8_HAVE_HW_SPI | |
#include <SPI.h> | |
#endif | |
struct display { | |
U8X8 *display; | |
uint8_t i2cnum; | |
uint8_t width; | |
uint8_t height; | |
}; | |
U8X8_SSD1306_128X64_NONAME_HW_I2C oled(U8X8_PIN_NONE); | |
#define NUMSCREENS 4 | |
display OLEDS[NUMSCREENS] = { | |
{ &oled, 0}, | |
{ &oled, 1}, | |
{ &oled, 6}, | |
{ &oled, 7} | |
}; | |
#define TCAADDR 0x70 // I2C Multiplexer ADDR | |
void tcaselect(uint8_t i) { | |
if (i > 7) return; | |
Wire.beginTransmission(TCAADDR); | |
Wire.write(1 << i); | |
Wire.endTransmission(); | |
} | |
uint8_t dnum; // screen id | |
int inc = 0; | |
void setup(void) | |
{ | |
Serial.begin(115200); | |
while (!Serial); // Leonardo: wait for serial monitor | |
Wire.begin(); | |
for(uint8_t i=0;i<NUMSCREENS;i++) { | |
tcaselect(OLEDS[i].i2cnum); | |
OLEDS[i].display->begin(); | |
} | |
} | |
void loop(void) { | |
dnum++; | |
if(dnum>=NUMSCREENS) { | |
dnum = 0; | |
} | |
String str = String(inc); | |
char test[16]; | |
str.toCharArray(test,16); | |
for (uint8_t f=0; f< NUMSCREENS; f++) { | |
display curDisplay = OLEDS[dnum]; | |
U8X8 *display = curDisplay.display; | |
tcaselect(curDisplay.i2cnum); | |
display->setFont(u8x8_font_chroma48medium8_r); | |
display->drawString(0,0, test); | |
display->refreshDisplay(); // only required for SSD1606/7 | |
} | |
inc++; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment