HiLetgo 128x64 OLED LCDを
動作確認と
内部
SSD1306で
https://github.com/adafruit/Adafruit_SSD1306
サンプルスケッチを
今回は
hello
の
#include <SPI.h>
#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
#define OLED_DC 6
#define OLED_CS 7
#define OLED_RESET 8
Adafruit_SSD1306 display(
SCREEN_WIDTH,
SCREEN_HEIGHT,
&SPI,
OLED_DC,
OLED_RESET,
OLED_CS
);
int16_t x = 0;
int16_t y = 0;
int16_t dirX = 1;
int16_t dirY = 1;
void setup() {
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if(!display.begin(SSD1306_SWITCHCAPVCC)) {
for(;;); // Don't proceed, loop forever
}
delay(1000);
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(1);
display.setCursor(x, y);
}
void loop() {
display.clearDisplay();
display.setCursor(x, y);
display.print(F("hello"));
display.display();
delay(10);
int16_t x1, y1;
uint16_t w, h;
x += dirX * 1;
y += dirY * 1;
display.getTextBounds(F("hello"), x, y, &x1, &y1, &w, &h);
if (x1 + w >= SCREEN_WIDTH) {
dirX = -1;
} else if (x1 <= 0) {
dirX = 1;
}
if (y1 + h >= SCREEN_HEIGHT) {
dirY = -1;
} else if (y1 <= 0) {
dirY = 1;
}
}