久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 4741|回復: 5
打印 上一主題 下一主題
收起左側

SSD1306 OLED arduino例程

[復制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:258849 發(fā)表于 2017-12-7 21:51 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式

  1. /*********************************************************************
  2. This is an example for our Monochrome OLEDs based on SSD1306 drivers

  3.   Pick one up today in the adafruit shop!

  4. This example is for a 128x64 size display using I2C to communicate
  5. 3 pins are required to interface (2 I2C and one reset)

  6. Adafruit invests time and resources providing this open source code,  
  7. please support Adafruit and open-source hardware by purchasing  
  8. products from Adafruit!

  9. Written by Limor Fried/Ladyada  for Adafruit Industries.   
  10. BSD license, check license.txt for more information
  11. All text above, and the splash screen must be included in any redistribution
  12. *********************************************************************/  

  13. #include <SPI.h>  
  14. #include <Wire.h>  
  15. #include <Adafruit_GFX.h>  
  16. #include <Adafruit_SSD1306.h>  

  17. #define OLED_RESET 4  
  18. Adafruit_SSD1306 display(OLED_RESET);  

  19. #define NUMFLAKES 10  
  20. #define XPOS 0  
  21. #define YPOS 1  
  22. #define DELTAY 2  


  23. #define LOGO16_GLCD_HEIGHT 16   
  24. #define LOGO16_GLCD_WIDTH  16   
  25. static const unsigned char PROGMEM logo16_glcd_bmp[] =  
  26. { B00000000, B11000000,  
  27.   B00000001, B11000000,  
  28.   B00000001, B11000000,  
  29.   B00000011, B11100000,  
  30.   B11110011, B11100000,  
  31.   B11111110, B11111000,  
  32.   B01111110, B11111111,  
  33.   B00110011, B10011111,  
  34.   B00011111, B11111100,  
  35.   B00001101, B01110000,  
  36.   B00011011, B10100000,  
  37.   B00111111, B11100000,  
  38.   B00111111, B11110000,  
  39.   B01111100, B11110000,  
  40.   B01110000, B01110000,  
  41.   B00000000, B00110000 };  

  42. #if (SSD1306_LCDHEIGHT != 64)  
  43. #error("Height incorrect, please fix Adafruit_SSD1306.h!");  
  44. #endif  

  45. void setup()   {                  
  46.   Serial.begin(9600);  

  47.   // by default, we'll generate the high voltage from the 3.3v line internally! (neat!)  
  48.   display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initialize with the I2C addr 0x3D (for the 128x64)  
  49.   // init done  

  50.   // Show image buffer on the display hardware.  
  51.   // Since the buffer is intialized with an Adafruit splashscreen  
  52.   // internally, this will display the splashscreen.  
  53.   display.display();  
  54.   delay(2000);  

  55.   // Clear the buffer.  
  56.   display.clearDisplay();  

  57.   // draw a single pixel  
  58.   display.drawPixel(10, 10, WHITE);  
  59.   // Show the display buffer on the hardware.  
  60.   // NOTE: You _must_ call display after making any drawing commands  
  61.   // to make them visible on the display hardware!  
  62.   display.display();  
  63.   delay(2000);  
  64.   display.clearDisplay();  

  65.   // draw many lines  
  66.   testdrawline();  
  67.   display.display();  
  68.   delay(2000);  
  69.   display.clearDisplay();  

  70.   // draw rectangles  
  71.   testdrawrect();  
  72.   display.display();  
  73.   delay(2000);  
  74.   display.clearDisplay();  

  75.   // draw multiple rectangles  
  76.   testfillrect();  
  77.   display.display();  
  78.   delay(2000);  
  79.   display.clearDisplay();  

  80.   // draw mulitple circles  
  81.   testdrawcircle();  
  82.   display.display();  
  83.   delay(2000);  
  84.   display.clearDisplay();  

  85.   // draw a white circle, 10 pixel radius  
  86.   display.fillCircle(display.width()/2, display.height()/2, 10, WHITE);  
  87.   display.display();  
  88.   delay(2000);  
  89.   display.clearDisplay();  

  90.   testdrawroundrect();  
  91.   delay(2000);  
  92.   display.clearDisplay();  

  93.   testfillroundrect();  
  94.   delay(2000);  
  95.   display.clearDisplay();  

  96.   testdrawtriangle();  
  97.   delay(2000);  
  98.   display.clearDisplay();  

  99.   testfilltriangle();  
  100.   delay(2000);  
  101.   display.clearDisplay();  

  102.   // draw the first ~12 characters in the font  
  103.   testdrawchar();  
  104.   display.display();  
  105.   delay(2000);  
  106.   display.clearDisplay();  

  107.   // draw scrolling text  
  108.   testscrolltext();  
  109.   delay(2000);  
  110.   display.clearDisplay();  

  111.   // text display tests  
  112.   display.setTextSize(1);  
  113.   display.setTextColor(WHITE);  
  114.   display.setCursor(0,0);  
  115.   display.println("Hello, world!");  
  116.   display.setTextColor(BLACK, WHITE); // 'inverted' text  
  117.   display.println(3.141592);  
  118.   display.setTextSize(2);  
  119.   display.setTextColor(WHITE);  
  120.   display.print("0x"); display.println(0xDEADBEEF, HEX);  
  121.   display.display();  
  122.   delay(2000);  
  123.   display.clearDisplay();  

  124.   // miniature bitmap display  
  125.   display.drawBitmap(30, 16,  logo16_glcd_bmp, 16, 16, 1);  
  126.   display.display();  
  127.   delay(1);  

  128.   // invert the display  
  129.   display.invertDisplay(true);  
  130.   delay(1000);   
  131.   display.invertDisplay(false);  
  132.   delay(1000);   
  133.   display.clearDisplay();  

  134.   // draw a bitmap icon and 'animate' movement  
  135.   testdrawbitmap(logo16_glcd_bmp, LOGO16_GLCD_HEIGHT, LOGO16_GLCD_WIDTH);  
  136. }  


  137. void loop() {  

  138. }  


  139. void testdrawbitmap(const uint8_t *bitmap, uint8_t w, uint8_t h) {  
  140.   uint8_t icons[NUMFLAKES][3];  

  141.   // initialize  
  142.   for (uint8_t f=0; f< NUMFLAKES; f++) {  
  143.     icons[f][XPOS] = random(display.width());  
  144.     icons[f][YPOS] = 0;  
  145.     icons[f][DELTAY] = random(5) + 1;  

  146.     Serial.print("x: ");  
  147.     Serial.print(icons[f][XPOS], DEC);  
  148.     Serial.print(" y: ");  
  149.     Serial.print(icons[f][YPOS], DEC);  
  150.     Serial.print(" dy: ");  
  151.     Serial.println(icons[f][DELTAY], DEC);  
  152.   }  

  153.   while (1) {  
  154.     // draw each icon  
  155.     for (uint8_t f=0; f< NUMFLAKES; f++) {  
  156.       display.drawBitmap(icons[f][XPOS], icons[f][YPOS], bitmap, w, h, WHITE);  
  157.     }  
  158.     display.display();  
  159.     delay(200);  

  160.     // then erase it + move it  
  161.     for (uint8_t f=0; f< NUMFLAKES; f++) {  
  162.       display.drawBitmap(icons[f][XPOS], icons[f][YPOS], bitmap, w, h, BLACK);  
  163.       // move it  
  164.       icons[f][YPOS] += icons[f][DELTAY];  
  165.       // if its gone, reinit  
  166.       if (icons[f][YPOS] > display.height()) {  
  167.         icons[f][XPOS] = random(display.width());  
  168.         icons[f][YPOS] = 0;  
  169.         icons[f][DELTAY] = random(5) + 1;  
  170.       }  
  171.     }  
  172.    }  
  173. }  


  174. void testdrawchar(void) {  
  175.   display.setTextSize(1);  
  176.   display.setTextColor(WHITE);  
  177.   display.setCursor(0,0);  

  178.   for (uint8_t i=0; i < 168; i++) {  
  179.     if (i == '\n') continue;  
  180.     display.write(i);  
  181.     if ((i > 0) && (i % 21 == 0))  
  182.       display.println();  
  183.   }      
  184.   display.display();  
  185.   delay(1);  
  186. }  

  187. void testdrawcircle(void) {  
  188.   for (int16_t i=0; i<display.height(); i+=2) {  
  189.     display.drawCircle(display.width()/2, display.height()/2, i, WHITE);  
  190.     display.display();  
  191.     delay(1);  
  192.   }  
  193. }  

  194. void testfillrect(void) {  
  195.   uint8_t color = 1;  
  196.   for (int16_t i=0; i<display.height()/2; i+=3) {  
  197.     // alternate colors  
  198.     display.fillRect(i, i, display.width()-i*2, display.height()-i*2, color%2);  
  199.     display.display();  
  200.     delay(1);  
  201.     color++;  
  202.   }  
  203. }  

  204. void testdrawtriangle(void) {  
  205.   for (int16_t i=0; i<min(display.width(),display.height())/2; i+=5) {  
  206.     display.drawTriangle(display.width()/2, display.height()/2-i,  
  207.                      display.width()/2-i, display.height()/2+i,  
  208.                      display.width()/2+i, display.height()/2+i, WHITE);  
  209.     display.display();  
  210.     delay(1);  
  211.   }  
  212. }  

  213. void testfilltriangle(void) {  
  214.   uint8_t color = WHITE;  
  215.   for (int16_t i=min(display.width(),display.height())/2; i>0; i-=5) {  
  216.     display.fillTriangle(display.width()/2, display.height()/2-i,  
  217.                      display.width()/2-i, display.height()/2+i,  
  218.                      display.width()/2+i, display.height()/2+i, WHITE);  
  219.     if (color == WHITE) color = BLACK;  
  220.     else color = WHITE;  
  221.     display.display();  
  222.     delay(1);  
  223.   }  
  224. }  

  225. void testdrawroundrect(void) {  
  226.   for (int16_t i=0; i<display.height()/2-2; i+=2) {  
  227.     display.drawRoundRect(i, i, display.width()-2*i, display.height()-2*i, display.height()/4, WHITE);  
  228.     display.display();  
  229.     delay(1);  
  230.   }  
  231. }  

  232. void testfillroundrect(void) {  
  233.   uint8_t color = WHITE;  
  234.   for (int16_t i=0; i<display.height()/2-2; i+=2) {  
  235.     display.fillRoundRect(i, i, display.width()-2*i, display.height()-2*i, display.height()/4, color);  
  236.     if (color == WHITE) color = BLACK;  
  237.     else color = WHITE;  
  238.     display.display();  
  239.     delay(1);  
  240.   }  
  241. }  

  242. void testdrawrect(void) {  
  243.   for (int16_t i=0; i<display.height()/2; i+=2) {  
  244.     display.drawRect(i, i, display.width()-2*i, display.height()-2*i, WHITE);  
  245.     display.display();  
  246.     delay(1);  
  247.   }  
  248. }  

  249. void testdrawline() {   
  250.   for (int16_t i=0; i<display.width(); i+=4) {  
  251.     display.drawLine(0, 0, i, display.height()-1, WHITE);  
  252.     display.display();  
  253.     delay(1);  
  254.   }  
  255.   for (int16_t i=0; i<display.height(); i+=4) {  
  256.     display.drawLine(0, 0, display.width()-1, i, WHITE);  
  257.     display.display();  
  258.     delay(1);  
  259.   }  
  260.   delay(250);  

  261.   display.clearDisplay();  
  262.   for (int16_t i=0; i<display.width(); i+=4) {  
  263.     display.drawLine(0, display.height()-1, i, 0, WHITE);  
  264.     display.display();  
  265.     delay(1);  
  266.   }  
  267.   for (int16_t i=display.height()-1; i>=0; i-=4) {  
  268.     display.drawLine(0, display.height()-1, display.width()-1, i, WHITE);  
  269.     display.display();  
  270.     delay(1);  
  271.   }  
  272.   delay(250);  

  273.   display.clearDisplay();  
  274.   for (int16_t i=display.width()-1; i>=0; i-=4) {  
  275.     display.drawLine(display.width()-1, display.height()-1, i, 0, WHITE);  
  276.     display.display();  
  277.     delay(1);  
  278.   }  
  279.   for (int16_t i=display.height()-1; i>=0; i-=4) {  
  280.     display.drawLine(display.width()-1, display.height()-1, 0, i, WHITE);  
  281.     display.display();  
  282.     delay(1);  
  283.   }  
  284.   delay(250);  

  285.   display.clearDisplay();  
  286.   for (int16_t i=0; i<display.height(); i+=4) {  
  287.     display.drawLine(display.width()-1, 0, 0, i, WHITE);  
  288.     display.display();  
  289.     delay(1);  
  290.   }  
  291.   for (int16_t i=0; i<display.width(); i+=4) {  
  292.     display.drawLine(display.width()-1, 0, i, display.height()-1, WHITE);   
  293.     display.display();  
  294.     delay(1);  
  295.   }  
  296.   delay(250);  
  297. }  

  298. void testscrolltext(void) {  
  299.   display.setTextSize(2);  
  300.   display.setTextColor(WHITE);  
  301.   display.setCursor(10,0);  
  302.   display.clearDisplay();  
  303.   display.println("scroll");  
  304.   display.display();  
  305.   delay(1);  

  306.   display.startscrollright(0x00, 0x0F);  
  307.   delay(2000);  
  308.   display.stopscroll();  
  309.   delay(1000);  
  310.   display.startscrollleft(0x00, 0x0F);  
  311.   delay(2000);  
  312.   display.stopscroll();  
  313.   delay(1000);      
  314.   display.startscrolldiagright(0x00, 0x07);  
  315.   delay(2000);  
  316.   display.startscrolldiagleft(0x00, 0x07);  
  317.   delay(2000);  
  318.   display.stopscroll();  
  319. }  

復制代碼
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復

使用道具 舉報

沙發(fā)
ID:280937 發(fā)表于 2018-9-19 20:04 來自手機 | 只看該作者
點解決我用NANO顯示不成功?
回復

使用道具 舉報

板凳
ID:280937 發(fā)表于 2018-9-19 20:04 來自手機 | 只看該作者
請指教
回復

使用道具 舉報

地板
ID:511799 發(fā)表于 2019-4-14 13:19 | 只看該作者
請問你這OLED的引腳定義的在哪里
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 99一级毛片 | 免费观看的黄色网址 | 色综合久久久久 | 午夜免费网站 | 亚洲日韩中文字幕一区 | 成人免费在线视频 | 免费v片在线观看 | 中文字幕av亚洲精品一部二部 | 久久亚洲国产精品 | 欧美久久久久久久久中文字幕 | 久久久久一区 | 亚洲精品九九 | 中国一级特黄真人毛片 | 午夜影院在线免费观看视频 | 亚洲欧美日韩在线一区二区 | 久久久久亚洲 | av日韩一区 | 国产一级免费视频 | 免费视频二区 | 欧美精品在线观看 | 亚洲一二三区av | 亚洲国产一区二区视频 | 天天躁日日躁狠狠很躁 | 久草在线免费资源 | 亚洲欧美精| 天天天操天天天干 | 黄色av网站在线观看 | 欧美久久久久久久久 | 天天视频一区二区三区 | 国产精品1 | 亚洲成人av在线播放 | 狠狠爱视频 | 久草免费福利 | 91九色porny首页最多播放 | 91精品国产综合久久久久久首页 | 日韩av在线一区 | 特黄级国产片 | 亚洲国产看片 | 欧美看片 | 亚洲精品一区二区三区四区高清 | 日韩在线免费视频 |