极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 16874|回复: 6

7针(7脚)oled显示屏的补充资料

[复制链接]
发表于 2016-12-7 19:50:43 | 显示全部楼层 |阅读模式
关于七针Oled显示屏的使用
七针olde显示屏有很多帖子介绍过,自己摸索了一遍但总是出这样那样的问题,其实7针oled不需要接VCC和GND,只需要接5个针脚即可:
上图


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复

使用道具 举报

 楼主| 发表于 2016-12-7 19:55:03 | 显示全部楼层
  1. /*

  2.   GraphicsTest.pde
  3.   
  4.   >>> Before compiling: Please remove comment from the constructor of the
  5.   >>> connected graphics display (see below).
  6.   
  7.   Universal 8bit Graphics Library, https://github.com/olikraus/u8glib/
  8.   
  9.   Copyright (c) 2012, [email protected]
  10.   All rights reserved.

  11.   Redistribution and use in source and binary forms, with or without modification,
  12.   are permitted provided that the following conditions are met:

  13.   * Redistributions of source code must retain the above copyright notice, this list
  14.     of conditions and the following disclaimer.
  15.    
  16.   * Redistributions in binary form must reproduce the above copyright notice, this
  17.     list of conditions and the following disclaimer in the documentation and/or other
  18.     materials provided with the distribution.

  19.   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  20.   CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  21.   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  22.   MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  23.   DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  24.   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25.   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  26.   NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  27.   LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  28.   CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  29.   STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  30.   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  31.   ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  


  32. */


  33. #include "U8glib.h"

  34. // setup u8g object, please remove comment from one of the following constructor calls
  35. // IMPORTANT NOTE: The following list is incomplete. The complete list of supported
  36. // devices with all constructor calls is here: https://github.com/olikraus/u8glib/wiki/device
  37. //U8GLIB_NHD27OLED_BW u8g(13, 11, 10, 9);        // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
  38. //U8GLIB_NHD27OLED_2X_BW u8g(13, 11, 10, 9);        // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
  39. //U8GLIB_NHD27OLED_GR u8g(13, 11, 10, 9);        // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
  40. //U8GLIB_NHD27OLED_2X_GR u8g(13, 11, 10, 9);        // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
  41. //U8GLIB_NHD31OLED_BW u8g(13, 11, 10, 9);        // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
  42. //U8GLIB_NHD31OLED_2X_BW u8g(13, 11, 10, 9);        // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
  43. //U8GLIB_NHD31OLED_GR u8g(13, 11, 10, 9);        // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
  44. //U8GLIB_NHD31OLED_2X_GR u8g(13, 11, 10, 9);        // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
  45. //U8GLIB_DOGS102 u8g(13, 11, 10, 9, 8);                // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
  46. //U8GLIB_DOGM132 u8g(13, 11, 10, 9);                // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
  47. //U8GLIB_DOGM128 u8g(13, 11, 10, 9);                // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
  48. //U8GLIB_DOGM128_2X u8g(13, 11, 10, 9);                // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
  49. //U8GLIB_ST7920_128X64_1X u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 17, 16);   // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, di=17,rw=16
  50. //U8GLIB_ST7920_128X64_4X u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 17, 16);   // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, di=17,rw=16
  51. //U8GLIB_ST7920_128X64_1X u8g(18, 16, 17);        // SPI Com: SCK = en = 18, MOSI = rw = 16, CS = di = 17
  52. //U8GLIB_ST7920_128X64_4X u8g(18, 16, 17);        // SPI Com: SCK = en = 18, MOSI = rw = 16, CS = di = 17
  53. //U8GLIB_ST7920_192X32_1X u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 17, 16);   // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, di=17,rw=16
  54. //U8GLIB_ST7920_192X32_4X u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 17, 16);   // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, di=17,rw=16
  55. //U8GLIB_ST7920_192X32_1X u8g(18, 16, 17);        // SPI Com: SCK = en = 18, MOSI = rw = 16, CS = di = 17
  56. //U8GLIB_ST7920_192X32_4X u8g(18, 16, 17);        // SPI Com: SCK = en = 18, MOSI = rw = 16, CS = di = 17
  57. //U8GLIB_ST7920_192X32_1X u8g(13, 11, 10);        // SPI Com: SCK = en = 13, MOSI = rw = 11, CS = di = 10
  58. //U8GLIB_ST7920_192X32_4X u8g(10);                // SPI Com: SCK = en = 13, MOSI = rw = 11, CS = di = 10, HW SPI
  59. //U8GLIB_ST7920_202X32_1X u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 17, 16);   // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, di=17,rw=16
  60. //U8GLIB_ST7920_202X32_4X u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 17, 16);   // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, di=17,rw=16
  61. //U8GLIB_ST7920_202X32_1X u8g(18, 16, 17);        // SPI Com: SCK = en = 18, MOSI = rw = 16, CS = di = 17
  62. //U8GLIB_ST7920_202X32_4X u8g(18, 16, 17);        // SPI Com: SCK = en = 18, MOSI = rw = 16, CS = di = 17
  63. //U8GLIB_LM6059 u8g(13, 11, 10, 9);                // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
  64. //U8GLIB_LM6063 u8g(13, 11, 10, 9);                // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
  65. //U8GLIB_DOGXL160_BW u8g(10, 9);                // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
  66. //U8GLIB_DOGXL160_GR u8g(13, 11, 10, 9);        // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
  67. //U8GLIB_DOGXL160_2X_BW u8g(13, 11, 10, 9);        // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
  68. //U8GLIB_DOGXL160_2X_GR u8g(13, 11, 10, 9);        // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
  69. //U8GLIB_PCD8544 u8g(13, 11, 10, 9, 8);                // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, Reset = 8
  70. //U8GLIB_PCF8812 u8g(13, 11, 10, 9, 8);                // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, Reset = 8
  71. //U8GLIB_KS0108_128 u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 14, 15, 17, 16);                 // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, cs1=14, cs2=15,di=17,rw=16
  72. //U8GLIB_LC7981_160X80 u8g(8, 9, 10, 11, 4, 5, 6, 7,  18, 14, 15, 17, 16);         // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, cs=14 ,di=15,rw=17, reset = 16
  73. //U8GLIB_LC7981_240X64 u8g(8, 9, 10, 11, 4, 5, 6, 7,  18, 14, 15, 17, 16);         // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, cs=14 ,di=15,rw=17, reset = 16
  74. //U8GLIB_LC7981_240X128 u8g(8, 9, 10, 11, 4, 5, 6, 7,  18, 14, 15, 17, 16);         // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, cs=14 ,di=15,rw=17, reset = 16
  75. //U8GLIB_ILI9325D_320x240 u8g(18,17,19,U8G_PIN_NONE,16 );                          // 8Bit Com: D0..D7: 0,1,2,3,4,5,6,7 en=wr=18, cs=17, rs=19, rd=U8G_PIN_NONE, reset = 16
  76. //U8GLIB_SBN1661_122X32 u8g(8,9,10,11,4,5,6,7,14,15, 17, U8G_PIN_NONE, 16);         // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 cs1=14, cs2=15,di=17,rw=16,reset = 16
  77. U8GLIB_SSD1306_128X64 u8g(13, 11, 10, 9);        // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
  78. //U8GLIB_SSD1306_128X64 u8g(4, 5, 6, 7);        // SW SPI Com: SCK = 4, MOSI = 5, CS = 6, A0 = 7 (new white HalTec OLED)
  79. //U8GLIB_SSD1306_128X64 u8g(10, 9);                // HW SPI Com: CS = 10, A0 = 9 (Hardware Pins are  SCK = 13 and MOSI = 11)
  80. //U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE|U8G_I2C_OPT_DEV_0);        // I2C / TWI
  81. //U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_DEV_0|U8G_I2C_OPT_NO_ACK|U8G_I2C_OPT_FAST);        // Fast I2C / TWI
  82. //U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NO_ACK);        // Display which does not send AC
  83. //U8GLIB_SSD1306_ADAFRUIT_128X64 u8g(13, 11, 10, 9);        // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
  84. //U8GLIB_SSD1306_ADAFRUIT_128X64 u8g(10, 9);                // HW SPI Com: CS = 10, A0 = 9 (Hardware Pins are  SCK = 13 and MOSI = 11)
  85. //U8GLIB_SSD1306_128X32 u8g(13, 11, 10, 9);        // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
  86. //U8GLIB_SSD1306_128X32 u8g(10, 9);             // HW SPI Com: CS = 10, A0 = 9 (Hardware Pins are  SCK = 13 and MOSI = 11)
  87. //U8GLIB_SSD1306_128X32 u8g(U8G_I2C_OPT_NONE);        // I2C / TWI
  88. //U8GLIB_SSD1306_64X48 u8g(13, 11, 10, 9);        // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
  89. //U8GLIB_SSD1306_64X48 u8g(10, 9);             // HW SPI Com: CS = 10, A0 = 9 (Hardware Pins are  SCK = 13 and MOSI = 11)
  90. //U8GLIB_SSD1306_64X48 u8g(U8G_I2C_OPT_NONE);        // I2C / TWI
  91. //U8GLIB_SH1106_128X64 u8g(13, 11, 10, 9);        // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
  92. //U8GLIB_SH1106_128X64 u8g(4, 5, 6, 7);        // SW SPI Com: SCK = 4, MOSI = 5, CS = 6, A0 = 7 (new blue HalTec OLED)
  93. //U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_NONE);        // I2C / TWI
  94. //U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_DEV_0|U8G_I2C_OPT_FAST);        // Dev 0, Fast I2C / TWI
  95. //U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_NO_ACK);        // Display which does not send ACK
  96. //U8GLIB_SSD1309_128X64 u8g(13, 11, 10, 9);        // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
  97. //U8GLIB_SSD1327_96X96_GR u8g(U8G_I2C_OPT_NONE);        // I2C
  98. //U8GLIB_SSD1327_96X96_2X_GR u8g(U8G_I2C_OPT_NONE);        // I2C
  99. //U8GLIB_UC1611_DOGM240 u8g(U8G_I2C_OPT_NONE);        // I2C
  100. //U8GLIB_UC1611_DOGM240 u8g(13, 11, 10, 9);        // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
  101. //U8GLIB_UC1611_DOGM240 u8g(10, 9);                // HW SPI Com: CS = 10, A0 = 9 (Hardware Pins are  SCK = 13 and MOSI = 11)
  102. //U8GLIB_UC1611_DOGM240 u8g(10, 9);                // HW SPI Com: CS = 10, A0 = 9 (Hardware Pins are  SCK = 13 and MOSI = 11)
  103. //U8GLIB_UC1611_DOGM240 u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 3, 17, 16);   // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, cs=3, di/a0=17,rw=16
  104. //U8GLIB_UC1611_DOGXL240 u8g(U8G_I2C_OPT_NONE);        // I2C
  105. //U8GLIB_UC1611_DOGXL240 u8g(13, 11, 10, 9);        // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
  106. //U8GLIB_UC1611_DOGXL240 u8g(10, 9);                // HW SPI Com: CS = 10, A0 = 9 (Hardware Pins are  SCK = 13 and MOSI = 11)
  107. //U8GLIB_UC1611_DOGXL240 u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 3, 17, 16);   // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, cs=3, di/a0=17,rw=16
  108. //U8GLIB_NHD_C12864 u8g(13, 11, 10, 9, 8);        // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8
  109. //U8GLIB_NHD_C12832 u8g(13, 11, 10, 9, 8);        // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8
  110. //U8GLIB_LD7032_60x32 u8g(13, 11, 10, 9, 8);        // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8
  111. //U8GLIB_LD7032_60x32 u8g(11, 12, 9, 10, 8);        // SPI Com: SCK = 11, MOSI = 12, CS = 9, A0 = 10, RST = 8  (SW SPI Nano Board)
  112. //U8GLIB_UC1608_240X64 u8g(13, 11, 10, 9, 8);        // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8
  113. //U8GLIB_UC1608_240X64_2X u8g(13, 11, 10, 9, 8);        // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8
  114. //U8GLIB_UC1608_240X64 u8g(10, 9, 8);        // HW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8
  115. //U8GLIB_UC1608_240X64_2X u8g(10, 9, 8);        // HW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8
  116. //U8GLIB_UC1608_240X u8g(13, 11, 10, 9, 8);        // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8
  117. //U8GLIB_UC1608_240X64_2X u8g(13, 11, 10, 9, 8);        // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8
  118. //U8GLIB_UC1608_240X64 u8g(10, 9, 8);        // HW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8
  119. //U8GLIB_UC1608_240X64_2X u8g(10, 9, 8);        // HW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8
  120. //U8GLIB_T6963_240X128 u8g(8, 9, 10, 11, 4, 5, 6, 7, 14, 15, 17, 18, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7, cs=14, a0=15, wr=17, rd=18, reset=16
  121. //U8GLIB_T6963_128X128 u8g(8, 9, 10, 11, 4, 5, 6, 7, 14, 15, 17, 18, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7, cs=14, a0=15, wr=17, rd=18, reset=16
  122. //U8GLIB_T6963_240X64 u8g(8, 9, 10, 11, 4, 5, 6, 7, 14, 15, 17, 18, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7, cs=14, a0=15, wr=17, rd=18, reset=16
  123. //U8GLIB_T6963_128X64 u8g(8, 9, 10, 11, 4, 5, 6, 7, 14, 15, 17, 18, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7, cs=14, a0=15, wr=17, rd=18, reset=16
  124. //U8GLIB_HT1632_24X16 u8g(3, 2, 4);                // WR = 3, DATA = 2, CS = 4
  125. //U8GLIB_SSD1351_128X128_332 u8g(13, 11, 8, 9, 7); // Arduino UNO: SW SPI Com: SCK = 13, MOSI = 11, CS = 8, A0 = 9, RESET = 7 (http://electronics.ilsoft.co.uk/ArduinoShield.aspx)
  126. //U8GLIB_SSD1351_128X128_332 u8g(76, 75, 8, 9, 7); // Arduino DUE: SW SPI Com: SCK = 13, MOSI = 11, CS = 8, A0 = 9, RESET = 7 (http://electronics.ilsoft.co.uk/ArduinoShield.aspx)
  127. //U8GLIB_SSD1351_128X128_332 u8g(8, 9, 7); // Arduino: HW SPI Com: SCK = 13, MOSI = 11, CS = 8, A0 = 9, RESET = 7 (http://electronics.ilsoft.co.uk/ArduinoShield.aspx)
  128. //U8GLIB_SSD1351_128X128_HICOLOR u8g(76, 75, 8, 9, 7); // Arduino DUE, SW SPI Com: SCK = 76, MOSI = 75, CS = 8, A0 = 9, RESET = 7 (http://electronics.ilsoft.co.uk/ArduinoShield.aspx)
  129. //U8GLIB_SSD1351_128X128_HICOLOR u8g(8, 9, 7); // Arduino, HW SPI Com: SCK = 76, MOSI = 75, CS = 8, A0 = 9, RESET = 7 (http://electronics.ilsoft.co.uk/ArduinoShield.aspx)
  130. //U8GLIB_SSD1351_128X128GH_332 u8g(8, 9, 7); // Arduino, HW SPI Com: SCK = 76, MOSI = 75, CS = 8, A0 = 9, RESET = 7 (Freetronics OLED)
  131. //U8GLIB_SSD1351_128X128GH_HICOLOR u8g(8, 9, 7); // Arduino, HW SPI Com: SCK = 76, MOSI = 75, CS = 8, A0 = 9, RESET = 7 (Freetronics OLED)

  132. void u8g_prepare(void) {
  133.   u8g.setFont(u8g_font_6x10);
  134.   u8g.setFontRefHeightExtendedText();
  135.   u8g.setDefaultForegroundColor();
  136.   u8g.setFontPosTop();
  137. }

  138. void u8g_box_frame(uint8_t a) {
  139.   u8g.drawStr( 0, 0, "drawBox");
  140.   u8g.drawBox(5,10,20,10);
  141.   u8g.drawBox(10+a,15,30,7);
  142.   u8g.drawStr( 0, 30, "drawFrame");
  143.   u8g.drawFrame(5,10+30,20,10);
  144.   u8g.drawFrame(10+a,15+30,30,7);
  145. }

  146. void u8g_disc_circle(uint8_t a) {
  147.   u8g.drawStr( 0, 0, "drawDisc");
  148.   u8g.drawDisc(10,18,9);
  149.   u8g.drawDisc(24+a,16,7);
  150.   u8g.drawStr( 0, 30, "drawCircle");
  151.   u8g.drawCircle(10,18+30,9);
  152.   u8g.drawCircle(24+a,16+30,7);
  153. }

  154. void u8g_r_frame(uint8_t a) {
  155.   u8g.drawStr( 0, 0, "drawRFrame/Box");
  156.   u8g.drawRFrame(5, 10,40,30, a+1);
  157.   u8g.drawRBox(50, 10,25,40, a+1);
  158. }

  159. void u8g_string(uint8_t a) {
  160.   u8g.drawStr(30+a,31, " 0");
  161.   u8g.drawStr90(30,31+a, " 90");
  162.   u8g.drawStr180(30-a,31, " 180");
  163.   u8g.drawStr270(30,31-a, " 270");
  164. }

  165. void u8g_line(uint8_t a) {
  166.   u8g.drawStr( 0, 0, "drawLine");
  167.   u8g.drawLine(7+a, 10, 40, 55);
  168.   u8g.drawLine(7+a*2, 10, 60, 55);
  169.   u8g.drawLine(7+a*3, 10, 80, 55);
  170.   u8g.drawLine(7+a*4, 10, 100, 55);
  171. }

  172. void u8g_triangle(uint8_t a) {
  173.   uint16_t offset = a;
  174.   u8g.drawStr( 0, 0, "drawTriangle");
  175.   u8g.drawTriangle(14,7, 45,30, 10,40);
  176.   u8g.drawTriangle(14+offset,7-offset, 45+offset,30-offset, 57+offset,10-offset);
  177.   u8g.drawTriangle(57+offset*2,10, 45+offset*2,30, 86+offset*2,53);
  178.   u8g.drawTriangle(10+offset,40+offset, 45+offset,30+offset, 86+offset,53+offset);
  179. }

  180. void u8g_ascii_1() {
  181.   char s[2] = " ";
  182.   uint8_t x, y;
  183.   u8g.drawStr( 0, 0, "ASCII page 1");
  184.   for( y = 0; y < 6; y++ ) {
  185.     for( x = 0; x < 16; x++ ) {
  186.       s[0] = y*16 + x + 32;
  187.       u8g.drawStr(x*7, y*10+10, s);
  188.     }
  189.   }
  190. }

  191. void u8g_ascii_2() {
  192.   char s[2] = " ";
  193.   uint8_t x, y;
  194.   u8g.drawStr( 0, 0, "ASCII page 2");
  195.   for( y = 0; y < 6; y++ ) {
  196.     for( x = 0; x < 16; x++ ) {
  197.       s[0] = y*16 + x + 160;
  198.       u8g.drawStr(x*7, y*10+10, s);
  199.     }
  200.   }
  201. }

  202. void u8g_extra_page(uint8_t a)
  203. {
  204.   if ( u8g.getMode() == U8G_MODE_HICOLOR || u8g.getMode() == U8G_MODE_R3G3B2) {
  205.     /* draw background (area is 128x128) */
  206.     u8g_uint_t r, g, b;
  207.     b = a << 5;
  208.     for( g = 0; g < 64; g++ )
  209.     {
  210.       for( r = 0; r < 64; r++ )
  211.       {
  212.         u8g.setRGB(r<<2, g<<2, b );
  213.         u8g.drawPixel(g, r);
  214.       }
  215.     }
  216.     u8g.setRGB(255,255,255);
  217.     u8g.drawStr( 66, 0, "Color Page");
  218.   }
  219.   else if ( u8g.getMode() == U8G_MODE_GRAY2BIT )
  220.   {
  221.     u8g.drawStr( 66, 0, "Gray Level");
  222.     u8g.setColorIndex(1);
  223.     u8g.drawBox(0, 4, 64, 32);   
  224.     u8g.drawBox(70, 20, 4, 12);
  225.     u8g.setColorIndex(2);
  226.     u8g.drawBox(0+1*a, 4+1*a, 64-2*a, 32-2*a);
  227.     u8g.drawBox(74, 20, 4, 12);
  228.     u8g.setColorIndex(3);
  229.     u8g.drawBox(0+2*a, 4+2*a, 64-4*a, 32-4*a);
  230.     u8g.drawBox(78, 20, 4, 12);
  231.   }
  232.   else
  233.   {
  234.     u8g.drawStr( 0, 12, "setScale2x2");
  235.     u8g.setScale2x2();
  236.     u8g.drawStr( 0, 6+a, "setScale2x2");
  237.     u8g.undoScale();
  238.   }
  239. }


  240. uint8_t draw_state = 0;

  241. void draw(void) {
  242.   u8g_prepare();
  243.   switch(draw_state >> 3) {
  244.     case 0: u8g_box_frame(draw_state&7); break;
  245.     case 1: u8g_disc_circle(draw_state&7); break;
  246.     case 2: u8g_r_frame(draw_state&7); break;
  247.     case 3: u8g_string(draw_state&7); break;
  248.     case 4: u8g_line(draw_state&7); break;
  249.     case 5: u8g_triangle(draw_state&7); break;
  250.     case 6: u8g_ascii_1(); break;
  251.     case 7: u8g_ascii_2(); break;
  252.     case 8: u8g_extra_page(draw_state&7); break;
  253.   }
  254. }

  255. void setup(void) {

  256.   // flip screen, if required
  257.   //u8g.setRot180();

  258. #if defined(ARDUINO)
  259.   pinMode(13, OUTPUT);           
  260.   digitalWrite(13, HIGH);  
  261. #endif
  262. }

  263. void loop(void) {
  264.   
  265.   // picture loop  
  266.   u8g.firstPage();  
  267.   do {
  268.     draw();
  269.   } while( u8g.nextPage() );
  270.   
  271.   // increase the state
  272.   draw_state++;
  273.   if ( draw_state >= 9*8 )
  274.     draw_state = 0;
  275.   
  276.   // rebuild the picture after some delay
  277.   delay(150);

  278. }
复制代码
回复 支持 1 反对 0

使用道具 举报

 楼主| 发表于 2016-12-7 19:54:41 | 显示全部楼层
/*

  GraphicsTest.pde
  
  >>> Before compiling: Please remove comment from the constructor of the
  >>> connected graphics display (see below).
  
  Universal 8bit Graphics Library, https://github.com/olikraus/u8glib/
  
  Copyright (c) 2012, [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 "U8glib.h"

// setup u8g object, please remove comment from one of the following constructor calls
// IMPORTANT NOTE: The following list is incomplete. The complete list of supported
// devices with all constructor calls is here: https://github.com/olikraus/u8glib/wiki/device
//U8GLIB_NHD27OLED_BW u8g(13, 11, 10, 9);        // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
//U8GLIB_NHD27OLED_2X_BW u8g(13, 11, 10, 9);        // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
//U8GLIB_NHD27OLED_GR u8g(13, 11, 10, 9);        // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
//U8GLIB_NHD27OLED_2X_GR u8g(13, 11, 10, 9);        // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
//U8GLIB_NHD31OLED_BW u8g(13, 11, 10, 9);        // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
//U8GLIB_NHD31OLED_2X_BW u8g(13, 11, 10, 9);        // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
//U8GLIB_NHD31OLED_GR u8g(13, 11, 10, 9);        // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
//U8GLIB_NHD31OLED_2X_GR u8g(13, 11, 10, 9);        // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
//U8GLIB_DOGS102 u8g(13, 11, 10, 9, 8);                // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
//U8GLIB_DOGM132 u8g(13, 11, 10, 9);                // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
//U8GLIB_DOGM128 u8g(13, 11, 10, 9);                // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
//U8GLIB_DOGM128_2X u8g(13, 11, 10, 9);                // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
//U8GLIB_ST7920_128X64_1X u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 17, 16);   // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, di=17,rw=16
//U8GLIB_ST7920_128X64_4X u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 17, 16);   // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, di=17,rw=16
//U8GLIB_ST7920_128X64_1X u8g(18, 16, 17);        // SPI Com: SCK = en = 18, MOSI = rw = 16, CS = di = 17
//U8GLIB_ST7920_128X64_4X u8g(18, 16, 17);        // SPI Com: SCK = en = 18, MOSI = rw = 16, CS = di = 17
//U8GLIB_ST7920_192X32_1X u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 17, 16);   // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, di=17,rw=16
//U8GLIB_ST7920_192X32_4X u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 17, 16);   // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, di=17,rw=16
//U8GLIB_ST7920_192X32_1X u8g(18, 16, 17);        // SPI Com: SCK = en = 18, MOSI = rw = 16, CS = di = 17
//U8GLIB_ST7920_192X32_4X u8g(18, 16, 17);        // SPI Com: SCK = en = 18, MOSI = rw = 16, CS = di = 17
//U8GLIB_ST7920_192X32_1X u8g(13, 11, 10);        // SPI Com: SCK = en = 13, MOSI = rw = 11, CS = di = 10
//U8GLIB_ST7920_192X32_4X u8g(10);                // SPI Com: SCK = en = 13, MOSI = rw = 11, CS = di = 10, HW SPI
//U8GLIB_ST7920_202X32_1X u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 17, 16);   // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, di=17,rw=16
//U8GLIB_ST7920_202X32_4X u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 17, 16);   // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, di=17,rw=16
//U8GLIB_ST7920_202X32_1X u8g(18, 16, 17);        // SPI Com: SCK = en = 18, MOSI = rw = 16, CS = di = 17
//U8GLIB_ST7920_202X32_4X u8g(18, 16, 17);        // SPI Com: SCK = en = 18, MOSI = rw = 16, CS = di = 17
//U8GLIB_LM6059 u8g(13, 11, 10, 9);                // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
//U8GLIB_LM6063 u8g(13, 11, 10, 9);                // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
//U8GLIB_DOGXL160_BW u8g(10, 9);                // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
//U8GLIB_DOGXL160_GR u8g(13, 11, 10, 9);        // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
//U8GLIB_DOGXL160_2X_BW u8g(13, 11, 10, 9);        // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
//U8GLIB_DOGXL160_2X_GR u8g(13, 11, 10, 9);        // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
//U8GLIB_PCD8544 u8g(13, 11, 10, 9, 8);                // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, Reset = 8
//U8GLIB_PCF8812 u8g(13, 11, 10, 9, 8);                // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, Reset = 8
//U8GLIB_KS0108_128 u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 14, 15, 17, 16);                 // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, cs1=14, cs2=15,di=17,rw=16
//U8GLIB_LC7981_160X80 u8g(8, 9, 10, 11, 4, 5, 6, 7,  18, 14, 15, 17, 16);         // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, cs=14 ,di=15,rw=17, reset = 16
//U8GLIB_LC7981_240X64 u8g(8, 9, 10, 11, 4, 5, 6, 7,  18, 14, 15, 17, 16);         // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, cs=14 ,di=15,rw=17, reset = 16
//U8GLIB_LC7981_240X128 u8g(8, 9, 10, 11, 4, 5, 6, 7,  18, 14, 15, 17, 16);         // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, cs=14 ,di=15,rw=17, reset = 16
//U8GLIB_ILI9325D_320x240 u8g(18,17,19,U8G_PIN_NONE,16 );                          // 8Bit Com: D0..D7: 0,1,2,3,4,5,6,7 en=wr=18, cs=17, rs=19, rd=U8G_PIN_NONE, reset = 16
//U8GLIB_SBN1661_122X32 u8g(8,9,10,11,4,5,6,7,14,15, 17, U8G_PIN_NONE, 16);         // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 cs1=14, cs2=15,di=17,rw=16,reset = 16
U8GLIB_SSD1306_128X64 u8g(13, 11, 10, 9);        // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
//U8GLIB_SSD1306_128X64 u8g(4, 5, 6, 7);        // SW SPI Com: SCK = 4, MOSI = 5, CS = 6, A0 = 7 (new white HalTec OLED)
//U8GLIB_SSD1306_128X64 u8g(10, 9);                // HW SPI Com: CS = 10, A0 = 9 (Hardware Pins are  SCK = 13 and MOSI = 11)
//U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE|U8G_I2C_OPT_DEV_0);        // I2C / TWI
//U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_DEV_0|U8G_I2C_OPT_NO_ACK|U8G_I2C_OPT_FAST);        // Fast I2C / TWI
//U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NO_ACK);        // Display which does not send AC
//U8GLIB_SSD1306_ADAFRUIT_128X64 u8g(13, 11, 10, 9);        // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
//U8GLIB_SSD1306_ADAFRUIT_128X64 u8g(10, 9);                // HW SPI Com: CS = 10, A0 = 9 (Hardware Pins are  SCK = 13 and MOSI = 11)
//U8GLIB_SSD1306_128X32 u8g(13, 11, 10, 9);        // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
//U8GLIB_SSD1306_128X32 u8g(10, 9);             // HW SPI Com: CS = 10, A0 = 9 (Hardware Pins are  SCK = 13 and MOSI = 11)
//U8GLIB_SSD1306_128X32 u8g(U8G_I2C_OPT_NONE);        // I2C / TWI
//U8GLIB_SSD1306_64X48 u8g(13, 11, 10, 9);        // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
//U8GLIB_SSD1306_64X48 u8g(10, 9);             // HW SPI Com: CS = 10, A0 = 9 (Hardware Pins are  SCK = 13 and MOSI = 11)
//U8GLIB_SSD1306_64X48 u8g(U8G_I2C_OPT_NONE);        // I2C / TWI
//U8GLIB_SH1106_128X64 u8g(13, 11, 10, 9);        // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
//U8GLIB_SH1106_128X64 u8g(4, 5, 6, 7);        // SW SPI Com: SCK = 4, MOSI = 5, CS = 6, A0 = 7 (new blue HalTec OLED)
//U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_NONE);        // I2C / TWI
//U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_DEV_0|U8G_I2C_OPT_FAST);        // Dev 0, Fast I2C / TWI
//U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_NO_ACK);        // Display which does not send ACK
//U8GLIB_SSD1309_128X64 u8g(13, 11, 10, 9);        // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
//U8GLIB_SSD1327_96X96_GR u8g(U8G_I2C_OPT_NONE);        // I2C
//U8GLIB_SSD1327_96X96_2X_GR u8g(U8G_I2C_OPT_NONE);        // I2C
//U8GLIB_UC1611_DOGM240 u8g(U8G_I2C_OPT_NONE);        // I2C
//U8GLIB_UC1611_DOGM240 u8g(13, 11, 10, 9);        // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
//U8GLIB_UC1611_DOGM240 u8g(10, 9);                // HW SPI Com: CS = 10, A0 = 9 (Hardware Pins are  SCK = 13 and MOSI = 11)
//U8GLIB_UC1611_DOGM240 u8g(10, 9);                // HW SPI Com: CS = 10, A0 = 9 (Hardware Pins are  SCK = 13 and MOSI = 11)
//U8GLIB_UC1611_DOGM240 u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 3, 17, 16);   // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, cs=3, di/a0=17,rw=16
//U8GLIB_UC1611_DOGXL240 u8g(U8G_I2C_OPT_NONE);        // I2C
//U8GLIB_UC1611_DOGXL240 u8g(13, 11, 10, 9);        // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
//U8GLIB_UC1611_DOGXL240 u8g(10, 9);                // HW SPI Com: CS = 10, A0 = 9 (Hardware Pins are  SCK = 13 and MOSI = 11)
//U8GLIB_UC1611_DOGXL240 u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 3, 17, 16);   // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, cs=3, di/a0=17,rw=16
//U8GLIB_NHD_C12864 u8g(13, 11, 10, 9, 8);        // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8
//U8GLIB_NHD_C12832 u8g(13, 11, 10, 9, 8);        // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8
//U8GLIB_LD7032_60x32 u8g(13, 11, 10, 9, 8);        // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8
//U8GLIB_LD7032_60x32 u8g(11, 12, 9, 10, 8);        // SPI Com: SCK = 11, MOSI = 12, CS = 9, A0 = 10, RST = 8  (SW SPI Nano Board)
//U8GLIB_UC1608_240X64 u8g(13, 11, 10, 9, 8);        // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8
//U8GLIB_UC1608_240X64_2X u8g(13, 11, 10, 9, 8);        // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8
//U8GLIB_UC1608_240X64 u8g(10, 9, 8);        // HW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8
//U8GLIB_UC1608_240X64_2X u8g(10, 9, 8);        // HW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8
//U8GLIB_UC1608_240X u8g(13, 11, 10, 9, 8);        // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8
//U8GLIB_UC1608_240X64_2X u8g(13, 11, 10, 9, 8);        // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8
//U8GLIB_UC1608_240X64 u8g(10, 9, 8);        // HW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8
//U8GLIB_UC1608_240X64_2X u8g(10, 9, 8);        // HW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8
//U8GLIB_T6963_240X128 u8g(8, 9, 10, 11, 4, 5, 6, 7, 14, 15, 17, 18, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7, cs=14, a0=15, wr=17, rd=18, reset=16
//U8GLIB_T6963_128X128 u8g(8, 9, 10, 11, 4, 5, 6, 7, 14, 15, 17, 18, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7, cs=14, a0=15, wr=17, rd=18, reset=16
//U8GLIB_T6963_240X64 u8g(8, 9, 10, 11, 4, 5, 6, 7, 14, 15, 17, 18, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7, cs=14, a0=15, wr=17, rd=18, reset=16
//U8GLIB_T6963_128X64 u8g(8, 9, 10, 11, 4, 5, 6, 7, 14, 15, 17, 18, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7, cs=14, a0=15, wr=17, rd=18, reset=16
//U8GLIB_HT1632_24X16 u8g(3, 2, 4);                // WR = 3, DATA = 2, CS = 4
//U8GLIB_SSD1351_128X128_332 u8g(13, 11, 8, 9, 7); // Arduino UNO: SW SPI Com: SCK = 13, MOSI = 11, CS = 8, A0 = 9, RESET = 7 (http://electronics.ilsoft.co.uk/ArduinoShield.aspx)
//U8GLIB_SSD1351_128X128_332 u8g(76, 75, 8, 9, 7); // Arduino DUE: SW SPI Com: SCK = 13, MOSI = 11, CS = 8, A0 = 9, RESET = 7 (http://electronics.ilsoft.co.uk/ArduinoShield.aspx)
//U8GLIB_SSD1351_128X128_332 u8g(8, 9, 7); // Arduino: HW SPI Com: SCK = 13, MOSI = 11, CS = 8, A0 = 9, RESET = 7 (http://electronics.ilsoft.co.uk/ArduinoShield.aspx)
//U8GLIB_SSD1351_128X128_HICOLOR u8g(76, 75, 8, 9, 7); // Arduino DUE, SW SPI Com: SCK = 76, MOSI = 75, CS = 8, A0 = 9, RESET = 7 (http://electronics.ilsoft.co.uk/ArduinoShield.aspx)
//U8GLIB_SSD1351_128X128_HICOLOR u8g(8, 9, 7); // Arduino, HW SPI Com: SCK = 76, MOSI = 75, CS = 8, A0 = 9, RESET = 7 (http://electronics.ilsoft.co.uk/ArduinoShield.aspx)
//U8GLIB_SSD1351_128X128GH_332 u8g(8, 9, 7); // Arduino, HW SPI Com: SCK = 76, MOSI = 75, CS = 8, A0 = 9, RESET = 7 (Freetronics OLED)
//U8GLIB_SSD1351_128X128GH_HICOLOR u8g(8, 9, 7); // Arduino, HW SPI Com: SCK = 76, MOSI = 75, CS = 8, A0 = 9, RESET = 7 (Freetronics OLED)

void u8g_prepare(void) {
  u8g.setFont(u8g_font_6x10);
  u8g.setFontRefHeightExtendedText();
  u8g.setDefaultForegroundColor();
  u8g.setFontPosTop();
}

void u8g_box_frame(uint8_t a) {
  u8g.drawStr( 0, 0, "drawBox");
  u8g.drawBox(5,10,20,10);
  u8g.drawBox(10+a,15,30,7);
  u8g.drawStr( 0, 30, "drawFrame");
  u8g.drawFrame(5,10+30,20,10);
  u8g.drawFrame(10+a,15+30,30,7);
}

void u8g_disc_circle(uint8_t a) {
  u8g.drawStr( 0, 0, "drawDisc");
  u8g.drawDisc(10,18,9);
  u8g.drawDisc(24+a,16,7);
  u8g.drawStr( 0, 30, "drawCircle");
  u8g.drawCircle(10,18+30,9);
  u8g.drawCircle(24+a,16+30,7);
}

void u8g_r_frame(uint8_t a) {
  u8g.drawStr( 0, 0, "drawRFrame/Box");
  u8g.drawRFrame(5, 10,40,30, a+1);
  u8g.drawRBox(50, 10,25,40, a+1);
}

void u8g_string(uint8_t a) {
  u8g.drawStr(30+a,31, " 0");
  u8g.drawStr90(30,31+a, " 90");
  u8g.drawStr180(30-a,31, " 180");
  u8g.drawStr270(30,31-a, " 270");
}

void u8g_line(uint8_t a) {
  u8g.drawStr( 0, 0, "drawLine");
  u8g.drawLine(7+a, 10, 40, 55);
  u8g.drawLine(7+a*2, 10, 60, 55);
  u8g.drawLine(7+a*3, 10, 80, 55);
  u8g.drawLine(7+a*4, 10, 100, 55);
}

void u8g_triangle(uint8_t a) {
  uint16_t offset = a;
  u8g.drawStr( 0, 0, "drawTriangle");
  u8g.drawTriangle(14,7, 45,30, 10,40);
  u8g.drawTriangle(14+offset,7-offset, 45+offset,30-offset, 57+offset,10-offset);
  u8g.drawTriangle(57+offset*2,10, 45+offset*2,30, 86+offset*2,53);
  u8g.drawTriangle(10+offset,40+offset, 45+offset,30+offset, 86+offset,53+offset);
}

void u8g_ascii_1() {
  char s[2] = " ";
  uint8_t x, y;
  u8g.drawStr( 0, 0, "ASCII page 1");
  for( y = 0; y < 6; y++ ) {
    for( x = 0; x < 16; x++ ) {
      s[0] = y*16 + x + 32;
      u8g.drawStr(x*7, y*10+10, s);
    }
  }
}

void u8g_ascii_2() {
  char s[2] = " ";
  uint8_t x, y;
  u8g.drawStr( 0, 0, "ASCII page 2");
  for( y = 0; y < 6; y++ ) {
    for( x = 0; x < 16; x++ ) {
      s[0] = y*16 + x + 160;
      u8g.drawStr(x*7, y*10+10, s);
    }
  }
}

void u8g_extra_page(uint8_t a)
{
  if ( u8g.getMode() == U8G_MODE_HICOLOR || u8g.getMode() == U8G_MODE_R3G3B2) {
    /* draw background (area is 128x128) */
    u8g_uint_t r, g, b;
    b = a << 5;
    for( g = 0; g < 64; g++ )
    {
      for( r = 0; r < 64; r++ )
      {
        u8g.setRGB(r<<2, g<<2, b );
        u8g.drawPixel(g, r);
      }
    }
    u8g.setRGB(255,255,255);
    u8g.drawStr( 66, 0, "Color Page");
  }
  else if ( u8g.getMode() == U8G_MODE_GRAY2BIT )
  {
    u8g.drawStr( 66, 0, "Gray Level");
    u8g.setColorIndex(1);
    u8g.drawBox(0, 4, 64, 32);   
    u8g.drawBox(70, 20, 4, 12);
    u8g.setColorIndex(2);
    u8g.drawBox(0+1*a, 4+1*a, 64-2*a, 32-2*a);
    u8g.drawBox(74, 20, 4, 12);
    u8g.setColorIndex(3);
    u8g.drawBox(0+2*a, 4+2*a, 64-4*a, 32-4*a);
    u8g.drawBox(78, 20, 4, 12);
  }
  else
  {
    u8g.drawStr( 0, 12, "setScale2x2");
    u8g.setScale2x2();
    u8g.drawStr( 0, 6+a, "setScale2x2");
    u8g.undoScale();
  }
}


uint8_t draw_state = 0;

void draw(void) {
  u8g_prepare();
  switch(draw_state >> 3) {
    case 0: u8g_box_frame(draw_state&7); break;
    case 1: u8g_disc_circle(draw_state&7); break;
    case 2: u8g_r_frame(draw_state&7); break;
    case 3: u8g_string(draw_state&7); break;
    case 4: u8g_line(draw_state&7); break;
    case 5: u8g_triangle(draw_state&7); break;
    case 6: u8g_ascii_1(); break;
    case 7: u8g_ascii_2(); break;
    case 8: u8g_extra_page(draw_state&7); break;
  }
}

void setup(void) {

  // flip screen, if required
  //u8g.setRot180();

#if defined(ARDUINO)
  pinMode(13, OUTPUT);           
  digitalWrite(13, HIGH);  
#endif
}

void loop(void) {
  
  // picture loop  
  u8g.firstPage();  
  do {
    draw();
  } while( u8g.nextPage() );
  
  // increase the state
  draw_state++;
  if ( draw_state >= 9*8 )
    draw_state = 0;
  
  // rebuild the picture after some delay
  delay(150);

}
回复 支持 反对

使用道具 举报

发表于 2016-12-9 11:39:39 | 显示全部楼层
有彩色的例子么?
回复 支持 反对

使用道具 举报

发表于 2016-12-10 17:14:38 | 显示全部楼层
这个感觉占内存好大,加个gps就基本满了
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-4-26 18:40 , Processed in 0.040537 second(s), 22 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表