极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 14404|回复: 0

张老师Microduino-OLED12864显示器图片移动的问题

[复制链接]
发表于 2013-8-3 08:07:10 | 显示全部楼层 |阅读模式
本帖最后由 tom 于 2013-8-6 23:25 编辑

张老师Microduino-OLED12864显示器图片移动的问题
本显示器驱动芯片是SSD1306
显示器如何连接,和显示字符串看另一个贴子http://www.geek-workshop.com/thread-5483-1-1.html

图片显示参阅我的另一篇贴子http://www.geek-workshop.com/thread-5527-1-1.html

本例中的图是一个256*64图片,宽度是12864的两倍,高度与屏幕相同。


void movePictureToRight(void)
图片从左向右移动,图片的第一点开始位置于屏幕的最右边(128,0),当它到达最左边时坐标(-128,0)
它的坐标轴X表达式=128-i*10,而它的Y轴坐标不变,为了能显示它Y轴坐标-25。即Y轴表达式=-25

0=-256+i*10  => i=25.6
程序表达式    display.drawBitmap( 128-i*10, -25, logo16_glcd_bmp, LOGO16_GLCD_WIDTH, LOGO16_GLCD_HEIGHT, 1);

本程序段完整表达为
void movePictureToRight(void)

{
  //由于str2.bmp图片尺寸是256=2*128
  //向左边移动,它的左边尺寸应该是X=128,高度选0
  //每次显示图片后,清屏,在它的左边减少10个像素,就能实现图片向左移动
  //移动变量定义为int i
  //每次移动10个像素,只需要26次就足够了256/10=25.6


  for (int i=0;i<=26;i++)
  {


    display.drawBitmap( 128-i*10, -25, logo16_glcd_bmp, LOGO16_GLCD_WIDTH, LOGO16_GLCD_HEIGHT, 1);
    //在指定的位置绘出图形  

    display.display();  //在12864液晶屏中显示出来   
    delay(50);
    display.clearDisplay();  //清屏
  }

}

至于其它的程序段与此类似,不再累述。(详见程序)

Arduino 完整的代码如下:
  1. *
  2. * // # Update the Adafruit SSD1306 library to make it work
  3. * // # Description:
  4. * // #                 show a simple animation
  5. *
  6. * // # Connection:
  7. * // #        SCL  -> A5(Uno)/D3(Leonardo)
  8. * // #        SDA  -> A4(Uno)/D2(Leonardo)
  9. * // #        RST  -> D4
  10. * // #        DC  -> GND
  11. * // #        3.3  -> 3.3v
  12. * // #        g  -> GND
  13. * // #
  14. *
  15.   *
  16. *
  17. * This example is for a 128x64 size display using I2C to communicate
  18. * 3 pins are required to interface (2 I2C and one reset)
  19. *
  20. * Adafruit invests time and resources providing this open source code,
  21. * please support Adafruit and open-source hardware by purchasing
  22. * products from Adafruit!
  23. * BSD license, check license.txt for more information
  24. * All text above, and the splash screen must be included in any redistribution
  25. *********************************************************************/

  26. #include <Wire.h>
  27. #include <Adafruit_GFX.h>
  28. #include <Adafruit_SSD1306.h>

  29. #define OLED_RESET 4
  30. SSD1306 display(OLED_RESET);

  31. #define NUMFLAKES 10
  32. #define XPOS 0
  33. #define YPOS 1
  34. #define DELTAY 2
  35. //本程序在IDE V1.01调试通过

  36. #define LOGO16_GLCD_HEIGHT 64 //图片高度
  37. #define LOGO16_GLCD_WIDTH  256 //图片宽度
  38. static unsigned char PROGMEM logo16_glcd_bmp[] =
  39. {
  40.   //本图片是汉字: 欢迎来到 极客工坊论坛
  41.   /*--  宽度x高度=256x64  --*/
  42.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  43.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  44.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  45.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  46.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  47.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  48.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  49.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  50.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  51.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  52.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  53.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  54.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  55.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  56.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  57.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  58.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  59.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  60.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  61.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  62.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  63.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  64.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  65.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  66.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  67.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  68.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  69.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  70.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  71.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  72.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  73.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  74.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  75.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  76.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  77.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  78.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  79.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  80.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  81.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  82.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  83.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  84.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  85.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  86.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  87.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  88.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  89.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  90.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  91.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  92.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  93.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  94.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  95.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  97.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  98.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  99.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  100.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  101.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  102.   0x00,0x00,0x00,0x00,0x10,0x00,0x04,0x00,0x0C,0x00,0x00,0x04,0x00,0x03,0x00,0x00,
  103.   0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  104.   0x00,0x00,0x00,0x00,0x10,0x00,0x0C,0x00,0x0C,0x00,0x07,0x04,0x00,0x03,0x00,0x00,
  105.   0x08,0x00,0x00,0x00,0x08,0x30,0x00,0x08,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,
  106.   0x00,0x00,0x00,0x00,0x30,0x06,0x18,0x00,0x0F,0x80,0x3E,0x04,0x00,0x03,0x03,0x81,
  107.   0x1F,0xE0,0x00,0x00,0x08,0x18,0x06,0x18,0x00,0x81,0xC0,0x00,0x00,0x00,0x00,0x00,
  108.   0x00,0x00,0x00,0x00,0x20,0x03,0x31,0xC0,0x7C,0x00,0x08,0x24,0x00,0x03,0x3D,0x81,
  109.   0xE0,0x60,0x01,0xE0,0x08,0x00,0x03,0x1C,0x00,0x8F,0x00,0x00,0x00,0x00,0x00,0x00,
  110.   0x00,0x00,0x00,0x0F,0x2F,0x00,0x66,0x60,0x0C,0xC0,0x1A,0x24,0x00,0x03,0x99,0x03,
  111.   0x10,0x80,0x3F,0x00,0x08,0x07,0x80,0x36,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,
  112.   0x00,0x00,0x00,0x33,0x72,0x00,0x22,0x60,0x6D,0x80,0x13,0x24,0x00,0x1F,0x1B,0x02,
  113.   0x3E,0x00,0x03,0x00,0x0E,0xFE,0x00,0x23,0x00,0xE0,0x30,0x00,0x00,0x00,0x00,0x00,
  114.   0x00,0x00,0x00,0x02,0x84,0x07,0x22,0x40,0x2C,0x00,0x7D,0x24,0x00,0x03,0x12,0x00,
  115.   0x46,0x00,0x03,0x00,0x38,0x10,0x00,0x61,0xC3,0x83,0xF8,0x00,0x00,0x00,0x00,0x00,
  116.   0x00,0x00,0x00,0x12,0x30,0x0D,0x2B,0xC0,0x0F,0xE0,0x48,0x24,0x00,0x03,0x17,0x00,
  117.   0xAC,0x00,0x03,0x00,0x08,0x30,0x0E,0x40,0xF0,0xBE,0x00,0x00,0x00,0x00,0x00,0x00,
  118.   0x00,0x00,0x00,0x0A,0x30,0x02,0x32,0xC1,0xFC,0x00,0x0E,0x24,0x00,0x06,0xB1,0x00,
  119.   0x18,0x00,0x02,0x00,0x08,0x3E,0x3A,0x93,0x00,0x82,0x00,0x00,0x00,0x00,0x00,0x00,
  120.   0x00,0x00,0x00,0x04,0x30,0x02,0x62,0x00,0x1A,0x00,0x3C,0x24,0x00,0x0A,0x2B,0x00,
  121.   0x37,0x00,0x02,0x00,0x0E,0x46,0x02,0x16,0x00,0xA6,0x00,0x00,0x00,0x00,0x00,0x00,
  122.   0x00,0x00,0x00,0x06,0x28,0x03,0x02,0x00,0x39,0x80,0x08,0x24,0x00,0x12,0x2A,0x00,
  123.   0x61,0xC0,0x02,0x00,0x18,0xC4,0x04,0x1C,0x00,0xC4,0x80,0x00,0x00,0x00,0x00,0x00,
  124.   0x00,0x00,0x00,0x09,0x6C,0x01,0x02,0x00,0x68,0xE0,0x0F,0x84,0x00,0x02,0x46,0x01,
  125.   0xCF,0x78,0x03,0xFC,0x71,0x8C,0x04,0x90,0x81,0x88,0x40,0x00,0x00,0x00,0x00,0x00,
  126.   0x00,0x00,0x00,0x10,0x46,0x0F,0xF2,0x00,0xC8,0x7E,0xFC,0x04,0x00,0x02,0x89,0x86,
  127.   0x7B,0x00,0xFE,0x00,0x03,0x08,0x07,0x10,0x87,0x1F,0xE0,0x00,0x00,0x00,0x00,0x00,
  128.   0x00,0x00,0x00,0x20,0x83,0x00,0x1F,0xFB,0x08,0x00,0x60,0x14,0x00,0x02,0x30,0xE0,
  129.   0x42,0x00,0x00,0x00,0x06,0x38,0x06,0x1F,0xC0,0x10,0x20,0x00,0x00,0x00,0x00,0x00,
  130.   0x00,0x00,0x00,0x01,0x01,0xC0,0x03,0xE0,0x08,0x00,0x00,0x0C,0x00,0x02,0x00,0x00,
  131.   0x7E,0x00,0x00,0x00,0x00,0x30,0x04,0x0F,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  132.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x0C,0x00,0x00,0x00,0x00,
  133.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  134.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  135.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  136.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  137.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  138.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  139.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  140.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  141.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  142.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  143.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  144.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  145.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  146.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  147.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  148.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  149.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  150.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  151.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  152.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  153.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  154.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  155.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  156.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  157.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  158.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  159.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  160.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  161.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  162.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  163.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  164.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  165.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  166.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  167.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  168.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  169.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

  170. };

  171. #if (SSD1306_LCDHEIGHT != 64)
  172. #error("Height incorrect, please fix Adafruit_SSD1306.h!");
  173. #endif

  174. void setup()   {               
  175.   Serial.begin(9600);

  176.   display.begin(SSD1306_SWITCHCAPVCC, 0x3c);  // initialize with the I2C addr 0x3C (for the 128x64)
  177.   // init done
  178.   //初始化12864屏幕






  179. }

  180. void movePictureToRight(void)

  181. {
  182.   //由于str2.bmp图片尺寸是256=2*128
  183.   //向左边移动,它的左边尺寸应该是X=128,高度选0
  184.   //每次显示图片后,清屏,在它的左边减少10个像素,就能实现图片向左移动
  185.   //移动变量定义为int i
  186.   //每次移动10个像素,只需要26次就足够了256/10=25.6


  187.   for (int i=0;i<=26;i++)
  188.   {


  189.     display.drawBitmap( 128-i*10, -25, logo16_glcd_bmp, LOGO16_GLCD_WIDTH, LOGO16_GLCD_HEIGHT, 1);
  190.     //在指定的位置绘出图形  

  191.     display.display();  //在12864液晶屏中显示出来   
  192.     delay(50);
  193.     display.clearDisplay();  //清屏
  194.   }

  195. }

  196. void   movePictureToLeft(void)
  197. {

  198.   for (int i=0;i<=26;i++)
  199.   {

  200.     display.clearDisplay();  //清屏
  201.     display.drawBitmap( -256+i*10, -25, logo16_glcd_bmp, LOGO16_GLCD_WIDTH, LOGO16_GLCD_HEIGHT, 1);
  202.     //在指定的位置绘出图形  

  203.     display.display();  //在12864液晶屏中显示出来   
  204.     delay(100);

  205.   }

  206. }   

  207. void   movePictureToUp(void)
  208. {

  209.   for (int i=0;i<=7;i++)
  210.   {
  211.     for (int j=0;j<=26;j++)
  212.     {
  213.       display.clearDisplay();  //清屏
  214.       display.drawBitmap( 0-j*10, 64-i*10, logo16_glcd_bmp, LOGO16_GLCD_WIDTH, LOGO16_GLCD_HEIGHT, 1);
  215.       //在指定的位置绘出图形  

  216.       display.display();  //在12864液晶屏中显示出来   
  217.       delay(100);
  218.     }

  219.   }
  220. }

  221. void   movePictureToDown(void)
  222. {

  223.   for (int i=0;i<=7;i++)
  224.   {
  225.     for (int j=0;j<=26;j++)
  226.     {
  227.       display.clearDisplay();  //清屏
  228.       display.drawBitmap( 0-j*10, -64+i*10, logo16_glcd_bmp, LOGO16_GLCD_WIDTH, LOGO16_GLCD_HEIGHT, 1);
  229.       //在指定的位置绘出图形  

  230.       display.display();  //在12864液晶屏中显示出来   
  231.       delay(100);
  232.     }
  233.   }
  234. }
  235. uint8_t draw_state = 0;

  236. void mydraw(void) {

  237.   switch(draw_state >> 3) {
  238.   case 0:
  239.     movePictureToLeft();
  240.     break;
  241.   case 1:   
  242.     movePictureToRight() ;
  243.     break;
  244.   case 2:
  245.     movePictureToUp();
  246.     break;
  247.   case 3:
  248.     movePictureToDown();
  249.     break;



  250.   }
  251. }

  252. void loop() {
  253.   mydraw();

  254.   draw_state++;
  255.   if ( draw_state >= 7*8 )
  256.     draw_state = 0;
  257. }



复制代码

评分

参与人数 1 +3 收起 理由
Microduino + 3

查看全部评分

回复

使用道具 举报

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

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

Archiver|联系我们|极客工坊

GMT+8, 2024-4-25 10:19 , Processed in 0.039569 second(s), 21 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

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