Keyestudio I2C 8x8 LED Matrix HT16K33 その②
- 2017/10/01
- 19:45
Keyestudio I2C 8x8 LED Matrix HT16K33 その②
こんにちはRoboTakaoです。ようこそ「極力ローコスト ロボット製作 ブログ」にお越しくださいました。
前回紹介したKeyestudio I2C 8x8 Matrix LEDですが、Arduino IDEにライブラリーをインストールするとスケッチ例からサンプルスケッチを使うことができます。
前回までの記事
今回はこのサンプルスケッチを改造して自分の表示させたい画像を出してみましょう。
まずスケッチ例からMatrix8x8を選択して、新しい名前で保存しておきます。
スケッチ例 → Adafruit LED Backpack Library1 → matrix8x8

各命令
このスケッチの中では幾つかの例が示されています。
1)clear( ) 画面消去
2)drawBitmap 8x8のビットマップ
drawBitmap(はじめのX座標 , はじめのY座標 , ビットマップ名 , 幅 , 高さ , 色) 色は今回は1色なのでLED_ONで指定
3)drawPixel ピクセルの描画
drawPixel( X座標 , Y座標 , 色) 今回は1色なのでLED_ONで指定
4)drawline 線の描画
drawline( はじめのX座標 , はじめのY座標 , おわりのX座標 , おわりのY座標 , 色) 色は今回は1色なのでLED_ONで指定
5)drawRect 四角の描画
drawRect ( はじめのX座標 , はじめのY座標 , おわりのX座標 , おわりのY座標 , 色) 色は今回は1色なのでLED_ONで指定
6)fillRect 塗りつぶした四角の描画
fillRect( はじめのX座標 , はじめのY座標 , おわりのX座標 ,おわりのY座標 , 色) 色は今回は1色なのでLED_ONで指定
7)drawCircle 円の描画
drawCircle( 中心のX座標 , 中心のY座標 , 半径 , 色)
8)テキストの処理
8−1)setTextSize テキストのサイズ
setTextSize( サイズ ) 今回は1
8−2)setTextWrap 折り返し?すいませんよくわかってません
8−3)setTextColor テキストの色
setTextColor( 色 ) 今回は1色なのでLED_ONで指定
8−3)setCursor テキストのカーソル位置
setCursor( X座標 , Y座標 )
8−4)print テキスト描画
print( “テキスト” )
9)writeDisplay 描画
10)setRotation 画面の回転
setRotation( 方向 ) 0〜3
それぞれ上記のAdafruit_GFXのメソッドで描画を設定して、writeDisplayと書けば描画される仕組みです。
さて、それぞれ命令はわかったところでサンプルスケッチをビットマップとテキストを変更したものを作ってみました。
ビットマップはエクセルとかで一旦書くとわかりやすいでしょう。

変更したスケッチ
#include
#include
#include "Adafruit_LEDBackpack.h"
Adafruit_8x8matrix matrix = Adafruit_8x8matrix();
void setup() {
Serial.begin(9600);
Serial.println("8x8 LED Matrix Test");
matrix.begin(0x70); // pass in the address
}
static const uint8_t PROGMEM
yujiman_bmp[] =
{ B01000010,
B00111100,
B01011010,
B10000001,
B10100101,
B10000001,
B01000010,
B00111100 },
yujimanU_bmp[] =
{ B01000010,
B00111100,
B01011010,
B10100101,
B10000001,
B10011001,
B01000010,
B00111100 };
void loop() {
matrix.setRotation(1);
matrix.clear();
matrix.drawBitmap(0, 0, yujiman_bmp, 8, 8, LED_ON);
matrix.writeDisplay();
delay(1000);
matrix.clear();
matrix.drawBitmap(0, 0, yujimanU_bmp, 8, 8, LED_ON);
matrix.writeDisplay();
delay(1000);
matrix.setRotation(1);
matrix.clear();
matrix.drawBitmap(0, 0, yujiman_bmp, 8, 8, LED_ON);
matrix.writeDisplay();
delay(1000);
matrix.clear();
matrix.drawBitmap(0, 0, yujimanU_bmp, 8, 8, LED_ON);
matrix.writeDisplay();
delay(1000);
matrix.setTextSize(1);
matrix.setTextWrap(false); // we dont want text to wrap so it scrolls nicely
matrix.setTextColor(LED_ON);
for (int8_t x=0; x>=-46; x--) {
matrix.clear();
matrix.setCursor(x,0);
matrix.print("RoboTAKAO");
matrix.writeDisplay();
delay(100);
}
}
それでは今回はこの辺で失礼します!ありがとうございました。
スポンサードリンク