DigisparkとOLEDの実験 (0.96" 128×64)
Arduino、DigisparkでOLEDディスプレイを使ってみましょう。OLEDディスプレイの実験をしています。これを駆動するArduinoはDigispark。通常のArduinoUnoの場合Adafruitのライブラリを使えば簡単に動きます。しかし、Digisparkの場合適当なライブラリがなく苦労したので、ここに備忘録を残しておきます。
DigisparkのI2Cピン
- SDA:P0
- SCL:P3
ディスプレイの仕組み
図のように座標は、横0~128だが、縦は0~8までしかない。そして一箇所ごとに縦に8Bitが格納できる。
動作の様子
コード
Digisparkのボード、ドライバはインストール済みであること。
Digisparkは書き込む前にUSBを繋いではいけない。書込み後、IDE下部の表示を見てUSBを繋ぐこと。
※https://github.com/McNeight/TinySSD1306
でいけるかも?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <TinySSD1306.h> | |
#include <Wire.h> | |
void setup() { | |
display.ssd1306_begin(); // initialize with the I2C addr 0x3C (for the 128x64) | |
randomSeed(analogRead(0)); | |
display.ssd1306_setpos(0,0); | |
} | |
void loop() { | |
int width = 128; | |
int height = 32; | |
int i,j,k; | |
int w,b,column; | |
w = 10; | |
b = 8; | |
column = 8; | |
int D = B00000001; | |
int x0,y0; | |
x0=0; | |
y0=0; | |
display.ssd1306_fill_area(); | |
for(k=0;k<column;k++){ | |
for(j=0;j<b;j++){ | |
display.ssd1306_setpos(0,k); | |
for(i=0;i<width;i++){ | |
display.ssd1306_data(D); | |
delay(w); | |
} | |
D = D * 2 + 1; | |
} | |
D = B00000001; | |
} | |
} |
Post a Comment