代码
#include <Wire.h>
#include "SSD1306.h"
unsigned char image[] = {
/*-- 调入了一幅图像:C:\Users\chen\Desktop\未命名绘图.bmp --*/
/*-- 宽度x高度=32x32 --*/
0x00,0x00,0x80,0x00,0x00,0x01,0xC0,0x00,0x00,0x01,0xC0,0x00,0x00,0x03,0xE0,0x00,
0x00,0x07,0xE0,0x00,0x00,0x07,0xF0,0x00,0x00,0x0F,0xF8,0x00,0x00,0x0F,0xF8,0x00,
0x00,0x1F,0xFC,0x00,0x00,0x1F,0xFC,0x00,0x00,0x3F,0xFE,0x00,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x3F,0xFC,0x00,
0x00,0x3F,0xFC,0x00,0x00,0x1F,0xF8,0x00,0x00,0x0F,0xF0,0x00,0x00,0x0F,0xF0,0x00,
0x00,0x07,0xE0,0x00,0x00,0x03,0xC0,0x00,0x00,0x03,0x80,0x00,0x00,0x01,0x80,0x00
};
SSD1306Wire display(0x3c, 21, 18);//实例化屏幕
unsigned char x = (128-32)/2,y = (64-32)/2;
void gotTouch12() {//触摸12引脚中断 向右移动
if(x != 127)
x++;
display.clear();
}
void gotTouch13() {//触摸13引脚中断 向左移动
if(x != 0)
x--;
display.clear();
}
void gotTouch14() {// 向下移动
if(y!=63)
y++;
display.clear();
}
void gotTouch27() {//向上移动
if(y!=0)
y--;
display.clear();
}
void setup() {
// put your setup code here, to run once:
touchAttachInterrupt(12,gotTouch12, 40);
touchAttachInterrupt(13,gotTouch13, 40);
touchAttachInterrupt(14,gotTouch14, 40);
touchAttachInterrupt(27,gotTouch27, 40);
//初始化引脚中断
display.init();//显示屏初始化
display.flipScreenVertically();//垂直翻转显示屏
}
void loop() {
// put your main code here, to run repeatedly:
OLED_State();//
}
void OLED_State(){
display.drawFastImage(x,y,32,32,image);
display.display();
}
