阿正的网易云音乐 - 创建于 2017

一个大学生的学习心得,与君共勉。

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

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

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

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

代码如下

 1 #include <Arduino.h>
 2 #include <U8x8lib.h>
 3 
 4 #ifdef U8X8_HAVE_HW_SPI
 5 #include <SPI.h>
 6 #endif
 7 U8X8_SSD1306_128X64_NONAME_SW_I2C u8x8(/* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE);   // OLEDs without Reset of the Display
 8 void setup(void)
 9 {
10   //u8x8.begin();//可以定义按键如下
11   u8x8.begin(/*Select=*/ 7, /*Right/Next=*/ A1, /*Left/Prev=*/ A2, /*Up=*/ A0, /*Down=*/ A3, /*Home/Cancel=*/ 8);  
12 
13   u8x8.setPowerSave(0);
14 }
15 void loop(void)
16 {
17   /*u8x8.setFont(u8x8_font_chroma48medium8_r);
18   u8x8.drawString(0,0,"Hello World!");
19   u8x8.refreshDisplay();
20   delay(2000);*/
21 
22    uint8_t r;  
23   u8x8.setFont(u8x8_font_chroma48medium8_r);  
24   r = u8x8_UserInterfaceMessage(u8x8.getU8x8(), "Message", "Box", NULL, " Ok \n Cancel ");  
25   if ( r == 0 )  
26   {  
27     u8x8.userInterfaceMessage("You pressed the", "Home/Quit", "Button", " Ok ");    
28   }  
29   else if ( r == 1 )  
30   {  
31     u8x8.userInterfaceMessage("You selected the", "Ok", "Button", " Ok ");    
32   }  
33   else if ( r == 2 )  
34   {  
35     u8x8.userInterfaceMessage("You selected the", "Cancel", "Button", " Ok ");    
36   }  
37 }

 

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

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

代码如下

 1 #include <SPI.h>  
 2 #include <Wire.h>  
 3 #include <Adafruit_GFX.h>  
 4 #include <Adafruit_SSD1306.h>  
 5   
 6 #define OLED_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xD8,0xFE,0xF3,0xFF,0xFF,0xB3,0xFF,0xFF,0x98,
36 0xF6,0xFF,0xEF,0x9F,0xB7,0xED,0xFF,0xF8,0x00,0x0E,0x6F,0x1B,0xB7,0x6D,0xE3,0xF8,
37 0xFF,0xFF,0xFE,0x3B,0xB7,0xFF,0xFF,0xF8,0xFF,0xFF,0xFE,0x3E,0xDB,0xFF,0xFF,0xFE,
38 0xE0,0x5F,0x77,0x1E,0xDB,0xFF,0xE3,0xFE,0xFF,0xF7,0x7F,0xBF,0xDB,0xFF,0xFF,0xFE,
39 0xFF,0xFF,0x7F,0xFB,0xDB,0xFF,0xFF,0xF8,0xFF,0xFF,0x7F,0xC3,0xD8,0x07,0xFC,0xD8,
40 0xFF,0xFF,0x7F,0xC3,0xFB,0xFF,0xFF,0xF8,0xFF,0xFF,0x79,0x9B,0xFF,0xFC,0x7F,0xF8,
41 0xE0,0x7F,0x61,0x9B,0x9F,0x6C,0xFF,0xD8,0xF7,0xFF,0xFD,0x9B,0xDF,0xFC,0x7F,0xD8,
42 0xFF,0xE1,0xFC,0x00,0xC7,0xFC,0x00,0x00/*"C:\Users\Administrator\Desktop\6464qrco000000000de_15134800003995111111111111111827.bmp",0*/};  
43     
44 #if (SSD1306_LCDHEIGHT != 64)  
45 #error("Height incorrect, please fix Adafruit_SSD1306.h!");  
46 #endif  
47   
48 void setup()   {                  
49   Serial.begin(9600);  
50   display.begin(SSD1306_SWITCHCAPVCC, 0x3C);   
51   display.clearDisplay();  
52    display.drawBitmap(0, 0, logo, 64, 64, 1); 
53 }  
54   
55 void loop() {  
56   //display.drawBitmap(0, 0, logo, 64, 64, 1);  //在坐标X0,Y0的位置开始显示图片  
57                                                //128是取模软件显示的宽度  
58                                                //64是取模软件显示的高度  
59  // display.display();                           //把缓存的都显示  
60   //delay(1);  
61     
62  // display.clearDisplay();     //清除屏幕  
63 }  

 

 

 

posted @ 2017-12-17 16:18  阿♛正  阅读(3493)  评论(0编辑  收藏  举报