Skip to content

Instantly share code, notes, and snippets.

@thata
Created September 11, 2023 14:56
Show Gist options
  • Save thata/e8f2c3a24df4dcf17f3841d52aabb883 to your computer and use it in GitHub Desktop.
Save thata/e8f2c3a24df4dcf17f3841d52aabb883 to your computer and use it in GitHub Desktop.
Arduino の digitalWrite だけで有機ELディスプレイ SSD1331 の電源をオン→オフ
#define sclk 9
#define mosi 10
#define rst 11
#define dc 12
#define cs 13
void initSPI() {
// Init basic control pins common to all connection types
pinMode(cs, OUTPUT);
digitalWrite(cs, HIGH); // deselect(データ送信の時だけ select = LOW にする)
pinMode(dc, OUTPUT);
digitalWrite(dc, HIGH); // Data mode
// sclkとmosiを初期化
pinMode(mosi, OUTPUT);
digitalWrite(mosi, LOW);
pinMode(sclk, OUTPUT);
digitalWrite(dc, LOW);
// rstを初期化
pinMode(rst, OUTPUT);
digitalWrite(rst, HIGH);
delay(100);
digitalWrite(rst, LOW);
delay(100);
digitalWrite(rst, HIGH);
delay(200);
}
// Display on (0xAF)
void displayOn() {
// display on (0xAF)
digitalWrite(cs, LOW); // cs start
digitalWrite(dc, LOW); // command start
spiWrite16(0xAF);
digitalWrite(dc, HIGH); // command end
digitalWrite(cs, HIGH); // cs end
}
// Display off (0xAE)
void displayOff() {
digitalWrite(cs, LOW); // cs start
digitalWrite(dc, LOW); // command start
spiWrite16(0xAE);
digitalWrite(dc, HIGH); // command end
digitalWrite(cs, HIGH); // cs end
}
void spiWrite16(uint16_t w) {
for (uint8_t bit = 0; bit < 16; bit++) {
if (w & 0x8000)
digitalWrite(mosi, HIGH);
else
digitalWrite(mosi, LOW);
digitalWrite(sclk, HIGH);
digitalWrite(sclk, LOW);
w <<= 1;
}
}
void setup() {
delay(1000);
initSPI();
displayOn();
delay(1000);
displayOff();
delay(1000);
displayOn();
delay(1000);
displayOff();
}
void loop() {
// put your main code here, to run repeatedly:
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment