0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Raspberry Pi Pico 2事始め5~Raspberry Pi Hat 1.3inch OLED HATを使おう2~

Posted at

Raspberry Pi Pico 2事始め4~Raspberry Pi Hat 1.3inch OLED HATを使おう~ の続きです。

今回は、基板についているスイッチを使えるようにしてみましょう。

SPI設定

ファイル⇒スケッチ例⇒Adafruit_SH110x⇒OLED_featherwing を開きます。
最初に、接続方式を I2C から SPI にスケッチを変更します。
ピン設定は各自のボード設定に合わせてください。

#define OLED_MOSI     19
#define OLED_CLK      18
#define OLED_DC       9
#define OLED_CS       22
#define OLED_RST      10

// Create the OLED display
Adafruit_SH1106G display = Adafruit_SH1106G(128, 64, OLED_MOSI, OLED_CLK, OLED_DC, OLED_RST, OLED_CS);

void setup内 も変更しておきます。

  display.begin(0, true); 

ボタン設定をしよう

ジョイスティックと各スイッチ の設定を行います。

#define BUTTON_A  27
#define BUTTON_B  28
#define BUTTON_C  26

#define BUTTON_UP  12
#define BUTTON_DOWN  20
#define BUTTON_Left  11
#define BUTTON_Right  14
#define BUTTON_Press  13

void setup内

  pinMode(BUTTON_UP, INPUT_PULLUP);
  pinMode(BUTTON_DOWN, INPUT_PULLUP);
  pinMode(BUTTON_Left, INPUT_PULLUP);
  pinMode(BUTTON_Right, INPUT_PULLUP);
  pinMode(BUTTON_Press, INPUT_PULLUP);

最後に loop内

  if (!digitalRead(BUTTON_A))     display.print("A");
  if (!digitalRead(BUTTON_B))     display.print("B");
  if (!digitalRead(BUTTON_C))     display.print("C");
  if (!digitalRead(BUTTON_UP))    display.print("UP");
  if (!digitalRead(BUTTON_DOWN))  display.print("DOWN");
  if (!digitalRead(BUTTON_Left))  display.print("Left");
  if (!digitalRead(BUTTON_Right)) display.print("Right");
  if (!digitalRead(BUTTON_Press)) display.print("Press");

画面をすべて描画すると画面外に出てしまうため、ボタンCをクリックするとディスプレイをクリアし、カーソルを(0.0)に移動させます。

  if (!digitalRead(BUTTON_C))     display.clearDisplay() ,  display.setCursor(0, 0);

以上で、1.3inch OLED HATが使えるようになります。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?