1.ESP8266
2.OLED 0.96
3.电脑+软件Arduino
1.首先导入库
#include
#include
#include
#include
2.定义
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
#define SCREEN_ADDRESS 0x3C
long allSecond = 3456000;
int a = 9;
int b = 9;
char bb = '.';
long val = 0;
3.初始化OLED
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
4.viod()方法
void setup() {
Serial.begin(9600);
Wire.begin(/*SDA*/12,/*SCL*/14);//设置引脚
display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS);//显示
}
5.loop()方法
void setup() {
Serial.begin(9600);
Wire.begin(/*SDA*/12,/*SCL*/14);
display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS);
val = random(0, 2);
}
void loop() {
if (val > 0.5) {
b--;
if (b == -1) {
b = 9;
a--;
if (a == -1) {
a = 9;
allSecond--;
}
}
display.clearDisplay();
display.drawBitmap(0, 0, logo_bmp, 128, 39, WHITE);
display.setCursor(0, 49);
display.println(allSecond);
display.drawChar(79, 49, bb, SSD1306_WHITE, SSD1306_WHITE, 2, 2);
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(92, 49);
display.println(a);
display.setCursor(103, 49);
display.println(b);
display.display();
} else {
display.clearDisplay();
display.drawBitmap(0, 0, logo_bmp2, 128, 51, WHITE);
display.display();
}
delay(10);
}
复制粘贴然后上传的开发版上,大功告成!!
#include
#include
#include
#include
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
#define SCREEN_ADDRESS 0x3C
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
long allSecond = 3456000;
int a = 9;
int b = 9;
char bb = '.';
long val = 0;
static const unsigned char PROGMEM logo_bmp[] =
{
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0XC0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X40,0X00,0X00,0X00,0X60,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X70,0X00,0X00,0X00,0X78,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X78,0X00,0X00,0X00,0X78,0X30,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0XF0,0X00,
0X00,0X7C,0X00,0X00,0X00,0X78,0X78,0X00,0X00,0X06,0X00,0X00,0X00,0X00,0XF8,0X00,
0X00,0XFE,0X00,0X00,0X00,0X7E,0XF8,0X00,0X00,0X0F,0X00,0X00,0X01,0X80,0XF8,0X00,
0X00,0XFE,0X3E,0X00,0X07,0XFD,0XFC,0X00,0X00,0X07,0XC0,0X00,0X03,0XE0,0XF8,0X00,
0X00,0XFF,0XFF,0X00,0X0F,0XFB,0XFC,0X00,0X00,0X0F,0XE0,0X00,0X0F,0XE0,0XF0,0X00,
0X01,0X1F,0XFF,0X80,0X0F,0XFF,0XCF,0XC0,0X00,0X0F,0XE0,0X00,0XDF,0XE0,0XF0,0X00,
0X01,0XFF,0XFF,0X80,0X07,0XFF,0XFF,0XE0,0X00,0X0F,0XE0,0X00,0XFF,0XDC,0XF0,0X00,
0X3F,0XFF,0X67,0X80,0X03,0XFF,0XFF,0XF0,0X00,0X1F,0XE0,0X00,0XF3,0XDC,0XFE,0X00,
0X3F,0XFC,0XF0,0X00,0X00,0XFF,0XFF,0XF0,0X00,0X1F,0XC0,0X00,0XF3,0XBC,0XFF,0X00,
0X1F,0XF3,0XF8,0X00,0X0F,0XFF,0XFF,0XF9,0X8E,0X9F,0XC0,0X00,0XF7,0XBF,0XFF,0X80,
0X0F,0XCE,0XF8,0X00,0XFF,0XFE,0X00,0X30,0XE7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F,0XFE,
0X3E,0XA3,0XEF,0XC0,0X03,0XFF,0XF8,0X01,0XFC,0X00,0X00,0X00,0X03,0XFF,0XFB,0XFE,
0X3D,0X9F,0XFF,0XC0,0X01,0XFF,0XF8,0X03,0XF8,0X00,0X00,0X00,0X03,0XDF,0XC7,0X00,
0X71,0XFF,0XDF,0XC0,0X00,0XFF,0XF8,0X07,0XF0,0X00,0X00,0X00,0X03,0XCF,0X0C,0X00,
0X00,0XFB,0XBF,0XC0,0X00,0X7F,0XF0,0X1F,0XC0,0X00,0X00,0X00,0X03,0XC0,0X18,0X00,
0X00,0X00,0X1F,0XC0,0X00,0X3F,0XE0,0X3F,0X00,0X00,0X00,0X00,0X03,0XC0,0X20,0X00,
0X00,0X00,0X0F,0XC0,0X00,0X0F,0XC0,0XFE,0X00,0X00,0X00,0X00,0X1F,0XC0,0X40,0X00,
0X00,0X00,0X07,0XC0,0X00,0X00,0X01,0XF8,0X00,0X00,0X00,0X00,0X0F,0XC0,0X00,0X00,
0X00,0X00,0X01,0XC0,0X00,0X00,0X07,0XE0,0X00,0X00,0X00,0X00,0X0F,0XC0,0X00,0X00,
0X00,0X00,0X00,0X80,0X00,0X00,0X1E,0X00,0X00,0X00,0X00,0X00,0X07,0XC0,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
};
static const unsigned char PROGMEM logo_bmp2[] =
{
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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XF0, 0XFF, 0XFF, 0XFF, 0XFF, 0X9F, 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, 0XFF,
0XFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF,
};
void setup() {
Serial.begin(9600);
Wire.begin(/*SDA*/12,/*SCL*/14);
display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS);
val = random(0, 2);
}
void loop() {
if (val > 0.5) {
b--;
if (b == -1) {
b = 9;
a--;
if (a == -1) {
a = 9;
allSecond--;
}
}
display.clearDisplay();
display.drawBitmap(0, 0, logo_bmp, 128, 39, WHITE);
display.setCursor(0, 49);
display.println(allSecond);
display.drawChar(79, 49, bb, SSD1306_WHITE, SSD1306_WHITE, 2, 2);
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(92, 49);
display.println(a);
display.setCursor(103, 49);
display.println(b);
display.display();
} else {
display.clearDisplay();
display.drawBitmap(0, 0, logo_bmp2, 128, 51, WHITE);
display.display();
}
delay(10);
}