#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_SHT31.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3C for 128x64
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
Adafruit_SHT31 sht31 = Adafruit_SHT31();
// 'ไม่มีตา2', 127x63px
const unsigned char robot [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x1f, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x07, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x43, 0xff, 0x00, 0x0f, 0xff, 0xc0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc8, 0x00, 0x03, 0x80, 0xf8, 0xf0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0xc8, 0x00, 0x00, 0x00, 0x1c, 0x18, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xc1, 0xc8, 0x00, 0x00, 0x00, 0x06, 0x0c, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x31, 0xc0, 0xc8, 0x00, 0x00, 0x00, 0x22, 0x06, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xc0, 0x48, 0x00, 0x00, 0x00, 0x13, 0x03, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x9e, 0x60, 0x48, 0x00, 0x00, 0x00, 0x0d, 0x81, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x03, 0x3b, 0x20, 0x68, 0x00, 0x00, 0x00, 0x04, 0xc0, 0x80, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x06, 0xc1, 0xb0, 0x68, 0x00, 0x00, 0x00, 0x02, 0xc0, 0x80, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x0f, 0x80, 0xd8, 0x68, 0x00, 0x00, 0x00, 0x02, 0x60, 0xc0, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x48, 0x24, 0x00, 0x00, 0x00, 0x01, 0x60, 0x40, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x2c, 0x24, 0x00, 0x00, 0x00, 0x01, 0x20, 0x40, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x34, 0x34, 0x00, 0x00, 0x00, 0x01, 0xb0, 0x60, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x16, 0x30, 0x00, 0x00, 0x00, 0x00, 0xb0, 0x60, 0x00, 0x00,
0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x12, 0x12, 0x00, 0x00, 0x00, 0x00, 0xb0, 0x60, 0x00, 0x00,
0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x0a, 0x12, 0x00, 0x00, 0x00, 0x00, 0x90, 0x60, 0x00, 0x00,
0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x0b, 0x1b, 0x00, 0x00, 0x00, 0x00, 0x90, 0x60, 0x00, 0x00,
0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x05, 0x09, 0x00, 0x00, 0x00, 0x00, 0x90, 0x60, 0x00, 0x00,
0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x05, 0x0d, 0x80, 0x00, 0x00, 0x00, 0x90, 0x60, 0x00, 0x00,
0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x05, 0x04, 0x80, 0x00, 0x00, 0x00, 0x90, 0x40, 0x00, 0x00,
0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x07, 0x06, 0xc0, 0x00, 0x00, 0x00, 0x90, 0x40, 0x00, 0x00,
0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x07, 0x0f, 0x40, 0x00, 0x00, 0x00, 0x90, 0xc0, 0x00, 0x00,
0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x07, 0x1f, 0x20, 0x00, 0x00, 0x01, 0x90, 0xc0, 0x00, 0x00,
0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x31, 0x90, 0x00, 0x00, 0x01, 0x31, 0x80, 0x00, 0x00,
0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0xe0, 0x88, 0x00, 0x00, 0x01, 0x21, 0x00, 0x00, 0x00,
0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x07, 0xa0, 0x0e, 0x00, 0x00, 0x03, 0x62, 0x00, 0x00, 0x00,
0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x07, 0x10, 0x7b, 0x00, 0x00, 0x06, 0x6c, 0x00, 0x00, 0x00,
0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x07, 0x0c, 0xfc, 0xc0, 0x00, 0x04, 0xf8, 0x00, 0x00, 0x00,
0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x07, 0x07, 0x3e, 0x38, 0x00, 0x19, 0xf0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x07, 0x00, 0x33, 0x0f, 0xc1, 0xe3, 0xc0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x05, 0x80, 0x00, 0x00, 0x07, 0x00, 0xc0, 0xe0, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x05, 0x80, 0x00, 0x00, 0x0e, 0x01, 0x80, 0x7c, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x05, 0x80, 0x00, 0x00, 0x0e, 0x03, 0x80, 0x3f, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x06, 0x80, 0x00, 0x00, 0x0e, 0x07, 0x00, 0x33, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x06, 0x80, 0x00, 0x00, 0x1c, 0x0f, 0x00, 0x23, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x06, 0xc0, 0x00, 0x00, 0x1c, 0x1e, 0x00, 0x23, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x02, 0xc0, 0x00, 0x00, 0x38, 0x3e, 0x00, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x03, 0x40, 0x00, 0x00, 0x78, 0x46, 0x00, 0x62, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x01, 0x60, 0x00, 0x00, 0x71, 0xc6, 0x00, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x01, 0xa0, 0x00, 0x00, 0xf3, 0x04, 0x00, 0x46, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xd0, 0x00, 0x01, 0xe6, 0x04, 0x00, 0x46, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xc8, 0x00, 0x03, 0xcc, 0x04, 0x00, 0x46, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x64, 0x00, 0x0d, 0xf8, 0x04, 0x00, 0xc4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x32, 0x00, 0x1b, 0xe0, 0x0c, 0x00, 0xcc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x19, 0x80, 0xff, 0x80, 0x0c, 0x00, 0xcc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x0c, 0x40, 0xff, 0x00, 0x0c, 0x01, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x03, 0x00, 0x7c, 0x00, 0x0f, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0xc1, 0xe0, 0x00, 0x1f, 0x01, 0x8c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x18, 0x01, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x01, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x01, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x01, 0x8f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x01, 0xdf, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xf1, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x03, 0xf0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xff, 0x00, 0x30, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00,
0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x03, 0x00, 0x10, 0x7f, 0x80, 0x00, 0x00, 0x00, 0x00,
0xf0, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xe0, 0x01, 0x80, 0x18, 0x77, 0xfe, 0x00, 0x00, 0x00, 0x00
};
// Array of all bitmaps for convenience. (Total bytes used to store images in PROGMEM = 1024)
const int robotallArray_LEN = 1;
const unsigned char* robotallArray[1] = {
robot
};
// 'ตาปกติ (1)', 24x12px
const unsigned char eyes [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x03, 0x80, 0x18, 0x84, 0x60, 0x10,
0x48, 0x20, 0x13, 0x4b, 0x20, 0x11, 0x48, 0x20, 0x0c, 0x86, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00
};
// Array of all bitmaps for convenience. (Total bytes used to store images in PROGMEM = 64)
const int eyesallArray_LEN = 1;
const unsigned char* eyesallArray[1] = {
eyes
};
void setup() {
// Serial.begin(9600);
// if (!sht31.begin(0x44)) {
// Serial.println("Couldn't find SHT31");
// while (1) delay(1);
// }
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for (;;);
}
display.clearDisplay();
// แสดงรูปหุ่นยนต์ที่ตำแหน่ง (0,0)
display.drawBitmap(0, 0, robot, 128, 63, 1);
display.drawBitmap(64, 10, eyes, 24, 12, 1);
// ตั้งค่าตำแหน่งของข้อความอุณหภูมิ
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0); // ตำแหน่งข้อความที่แสดงบนขวา
display.println("Temp:");
display.display();
delay(2000);
}
void loop() {
float temperature = sht31.readTemperature();
display.clearDisplay();
// แสดงรูปหุ่นยนต์ที่ตำแหน่ง (0,0)
display.drawBitmap(0, 0, robot, 128, 63, 1);
display.drawBitmap(64, 10, eyes, 24, 12, 1);
// แสดงข้อมูลอุณหภูมิที่ตำแหน่ง (70,0)
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0); // ตำแหน่งข้อความที่แสดงบนขวา
display.print("Temp: ");
display.print(temperature);
display.println(" C");
display.display();
delay(2000);
}
Loading
ssd1306
ssd1306