这次采用U8X8的方式,不再采用u8g2,因为后者一直报内存问题。所以采用了不占内存的u8x8模式

同时u8g2库文件的示例代码也是很牛逼的,

U8g2库I2C总线再次突破性调试成功-LMLPHP

里面还有message box 非常的可爱运行效果也非常棒!

代码如下

 #include <Arduino.h>
#include <U8x8lib.h> #ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
U8X8_SSD1306_128X64_NONAME_SW_I2C u8x8(/* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE); // OLEDs without Reset of the Display
void setup(void)
{
//u8x8.begin();//可以定义按键如下
u8x8.begin(/*Select=*/ , /*Right/Next=*/ A1, /*Left/Prev=*/ A2, /*Up=*/ A0, /*Down=*/ A3, /*Home/Cancel=*/ ); u8x8.setPowerSave();
}
void loop(void)
{
/*u8x8.setFont(u8x8_font_chroma48medium8_r);
u8x8.drawString(0,0,"Hello World!");
u8x8.refreshDisplay();
delay(2000);*/ uint8_t r;
u8x8.setFont(u8x8_font_chroma48medium8_r);
r = u8x8_UserInterfaceMessage(u8x8.getU8x8(), "Message", "Box", NULL, " Ok \n Cancel ");
if ( r == )
{
u8x8.userInterfaceMessage("You pressed the", "Home/Quit", "Button", " Ok ");
}
else if ( r == )
{
u8x8.userInterfaceMessage("You selected the", "Ok", "Button", " Ok ");
}
else if ( r == )
{
u8x8.userInterfaceMessage("You selected the", "Cancel", "Button", " Ok ");
}
}

再也没有出现之前的动不动就报内存不足的问题。

同时还可以自己生成位图进行显示,比如二维码,不过,识别起来很吃力

U8g2库I2C总线再次突破性调试成功-LMLPHP

代码如下

 #include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h> #define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET); static const unsigned char PROGMEM logo[] =
{
0x9F,0xFE,0x6C,0x38,0xFF,0x6F,0xFF,0xFE,0xBF,0xFE,0x6C,0x38,0xFF,0x6F,0xFF,0xFE,
0xFF,0xFF,0xEF,0xB8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0x77,0x1E,0xDB,0xFF,0xE3,0xFE,0xFF,0xF7,0x7F,0xBF,0xDB,0xFF,0xFF,0xFE,
0xFF,0xFF,0x7F,0xFB,0xDB,0xFF,0xFF,0xF8,0xFF,0xFF,0x7F,0xC3,0xD8,0x07,0xFC,0xD8,
0xFF,0xFF,0x7F,0xC3,0xFB,0xFF,0xFF,0xF8,0xFF,0xFF,0x79,0x9B,0xFF,0xFC,0x7F,0xF8,
0xE0,0x7F,0x61,0x9B,0x9F,0x6C,0xFF,0xD8,0xF7,0xFF,0xFD,0x9B,0xDF,0xFC,0x7F,0xD8,
0xFF,0xE1,0xFC,0x00,0xC7,0xFC,0x00,0x00/*"C:\Users\Administrator\Desktop\6464qrco000000000de_15134800003995111111111111111827.bmp",0*/}; #if (SSD1306_LCDHEIGHT != 64)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif void setup() {
Serial.begin();
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
display.drawBitmap(, , logo, , , );
} void loop() {
//display.drawBitmap(0, 0, logo, 64, 64, 1); //在坐标X0,Y0的位置开始显示图片
//128是取模软件显示的宽度
//64是取模软件显示的高度
// display.display(); //把缓存的都显示
//delay(1); // display.clearDisplay(); //清除屏幕
}

U8g2库I2C总线再次突破性调试成功-LMLPHP

05-08 15:24