#include <SPI.h> // include i2c
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// ตำแหน่ง x = 0 - 127, y = 0 -63
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
// initial (ความกว้าง, ความสูง, สื่อสารด้วยอะไร, reset ด้วยอะไร)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
// Adafruit_SSD1306 <name>(param, ....) เวลาอ้างถึงทำโดย name.<> ex display.<>
#define NUMFLAKES 10 // Number of snowflakes in the animation example
void updateDisplay() {
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(1);
display.setFont(NULL);
display.setCursor(30, 20);
display.println("HELLO WORLD");
display.setCursor(35, 35);
display.println("CHADAPORN");
display.display();
}
const unsigned char paper_plane [] PROGMEM = {
0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x03, 0xf0, 0x00, 0x00, 0x3f, 0xe3,
0x00, 0x01, 0xff, 0xc6, 0x00, 0x1f, 0xff, 0x8e, 0x00, 0xff, 0xff, 0x1e, 0x07, 0xff, 0xfe, 0x3c,
0x3f, 0xff, 0xfc, 0x7c, 0xff, 0xff, 0xf8, 0xfc, 0xff, 0xff, 0xf1, 0xf8, 0xff, 0xff, 0xe3, 0xf8,
0xff, 0xff, 0xc7, 0xf8, 0x7f, 0xff, 0x8f, 0xf8, 0x3f, 0xff, 0x1f, 0xf0, 0x1f, 0xfe, 0x3f, 0xf0,
0x0f, 0xfc, 0x7f, 0xf0, 0x07, 0xf8, 0xff, 0xe0, 0x07, 0xf1, 0xff, 0xe0, 0x07, 0xe3, 0xff, 0xe0,
0x07, 0xc7, 0xff, 0xe0, 0x07, 0x8f, 0xff, 0xc0, 0x07, 0x1f, 0xff, 0xc0, 0x06, 0x3f, 0xff, 0xc0,
0x00, 0x7f, 0xff, 0x80, 0x00, 0xff, 0xff, 0x80, 0x00, 0xff, 0xff, 0x80, 0x00, 0x01, 0xff, 0x00,
0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x1e, 0x00
};
void setup() {
Serial.begin(9600);
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
// เช้คว่าติดต่อได้ไหม
if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
delay(2000); // Pause for 2 seconds
}
void loop() {
// clear buffer
display.clearDisplay();
// set color
display.setTextColor(WHITE);
display.setCursor(10, 10);
display.println("Hello CPE345!!!");
display.display();
delay(2000);
display.clearDisplay();
display.drawLine(0, 0, 127, 0, WHITE);
display.drawLine(127, 0, 127, 63, WHITE);
display.drawLine(127, 63, 0, 63, WHITE);
display.drawLine(0, 63, 0, 0, WHITE);
display.display();
delay(2000);
display.drawRect(5, 5, 117, 53, WHITE);
display.display();
delay(2000);
display.clearDisplay();
updateDisplay();
display.display();
delay(2000);
display.clearDisplay();
display.drawBitmap(32, 20, paper_plane, 32, 32, WHITE);
display.display();
delay(2000);
}