工業製造
産業用モノのインターネット | 工業材料 | 機器のメンテナンスと修理 | 産業プログラミング |
home  MfgRobots >> 工業製造 >  >> Manufacturing Technology >> 製造プロセス

Bluetooth経由のスクロールテキストとAndroidコントロールを備えた8×8LEDマトリックスMAX7219チュートリアル

このArduinoチュートリアルでは、MAX7219ドライバーとArduinoボードを使用して8×8LEDマトリックスを制御する方法を学習します。詳細については、次のビデオを見るか、以下のチュートリアルを読むことができます。

概要

3つの例を作成します。最初の例では、MAX7219の基本的な動作原理を説明し、2番目の例では、8×8 LEDマトリックスのスクロールテキストがどのように機能するかを確認し、3番目の例ではそれらを制御します。 BluetoothとカスタムビルドのAndroidアプリケーションを介して。

MAX7219

それでは、MAX7219ドライバーを詳しく見てみましょう。このICは、Arduinoとの通信に3本のワイヤーを使用しながら64個の個別のLEDを駆動できます。さらに、複数のドライバーとマトリックスをデイジーチェーン接続し、同じ3本のワイヤーを使用できます。

64個のLEDは、ICの16個の出力ピンによって駆動されます。今の問題は、それがどのように可能であるかということです。同時に点灯するLEDの最大数は実際には8つです。 LEDは8×8セットの行と列として配置されています。したがって、MAX7219は非常に短い時間で各列をアクティブにすると同時に、各行も駆動します。したがって、列と行をすばやく切り替えることにより、人間の目は連続した光にしか気づきません。

一般的な8×8LEDマトリックスのピンが内部でどのように配置されているかに注意してください。したがって、自分でマトリックスを作成する場合は、それを検討する必要があります。

また、MAX7219の一般的なブレークアウトボードには、5VとICピン番号18の間に抵抗が付属していることに注意してください。抵抗は、LEDへの輝度または電流の流れを設定するために使用されます。

ICのデータシートの次の表は、LEDの順方向電圧降下に応じて使用する必要のある抵抗の値を示しています。

回路図

それでは、8×8LEDマトリックスモジュールをArduinoボードに接続しましょう。回路図は次のとおりです。

モジュールのVCCとGNDはArduinoの5VピンとGNDピンに接続され、他の3つのピンDIN、CLK、CSはArduinoボードの任意のデジタルピンに接続されます。複数のモジュールを接続する場合は、前のブレークアウトボードの出力ピンを新しいモジュールの入力ピンに接続するだけです。実際、これらのピンは、前のボードのDOUTピンが新しいボードのDINピンに接続されていることを除いて、すべて同じです。

このArduinoチュートリアルに必要なコンポーネントは、以下のリンクから入手できます。

  • 8×8LEDMAX7219ドットマトリックスモジュール…..
  • HC-05Bluetoothモジュール………………………
  • Arduinoボード……………………………………..
  • ブレッドボードとジャンパー線…………………
基本的なMAX7219Arduinoコード

モジュールを接続したら、最初の例のArduinoコードを確認する準備が整いました。 GitHubからダウンロードできるMaxMatrixライブラリを使用します。

/*
      8x8 LED Matrix MAX7219 Example 01

   by Dejan Nedelkovski, www.HowToMechatronics.com

   Based on the following library:
   GitHub | riyas-org/max7219  https://github.com/riyas-org/max7219
*/

#include <MaxMatrix.h>

int DIN = 7;   // DIN pin of MAX7219 module
int CLK = 6;   // CLK pin of MAX7219 module
int CS = 5;    // CS pin of MAX7219 module
int maxInUse = 1;


MaxMatrix m(DIN, CS, CLK, maxInUse); 

char A[] = {4, 8,
            B01111110,
            B00010001,
            B00010001,
            B01111110,
           };

char B[] = {4, 8,
            B01111111,
            B01001001,
            B01001001,
            B00110110,
           };

char smile01[] = {8, 8,
                  B00111100,
                  B01000010,
                  B10010101,
                  B10100001,
                  B10100001,
                  B10010101,
                  B01000010,
                  B00111100
                 };
char smile02[] = {8, 8,
                  B00111100,
                  B01000010,
                  B10010101,
                  B10010001,
                  B10010001,
                  B10010101,
                  B01000010,
                  B00111100
                 };
char smile03[] = {8, 8,
                  B00111100,
                  B01000010,
                  B10100101,
                  B10010001,
                  B10010001,
                  B10100101,
                  B01000010,
                  B00111100
                 };

void setup() {
  m.init(); // MAX7219 initialization
  m.setIntensity(8); // initial led matrix intensity, 0-15
}

void loop() {
  // Seting the LEDs On or Off at x,y or row,column position
  m.setDot(6,2,true); 
  delay(1000);
  m.setDot(6,3,true);
  delay(1000);
  m.clear(); // Clears the display
  for (int i=0; i<8; i++){
    m.setDot(i,i,true);
    delay(300);
  }
  m.clear();
  // Displaying the character at x,y (upper left corner of the character)  
  m.writeSprite(2, 0, A);
  delay(1000);

  m.writeSprite(2, 0, B);
  delay(1000);

  m.writeSprite(0, 0, smile01);
  delay(1000);
  
  m.writeSprite(0, 0, smile02);
  delay(1000);
  
  m.writeSprite(0, 0, smile03);
  delay(1000);
  
  for (int i=0; i<8; i++){
    m.shiftLeft(false,false);
    delay(300);
  }
  m.clear();

}
Code language: Arduino (arduino)

説明: したがって、最初にMaxMatrix.hライブラリを含め、モジュールが接続されるピンを定義し、使用するモジュールの数を設定し、MaxMatrixオブジェクトを定義する必要があります。

文字を表示するには、文字またはバイトの配列でそれらを定義する必要があります。ここにいくつかの例があります。ビットが実際には0と1である文字をどのように形成しているかがわかります。この場合、それらは90度回転しますが、ライブラリの例では、後でテキストをスクロールするためのshiftLeftカスタム関数を実装するのが簡単になるようにそれらを使用することを提案しています。

セットアップセクションでは、モジュールを初期化し、LEDの明るさを設定する必要があります。 setDot()関数を使用するループセクションでは、X、Y、または行/列の位置で点灯するように個々のLEDを設定でき、clear()関数を使用して表示をクリアできます。

事前定義された文字を表示するには、writeSprite()関数を使用します。最初の2つの引数は、文字の左上隅のX位置とY位置です。最後に、shiftLeft()関数を使用して、文字を左に移動またはスクロールします。

8×8LEDマトリックススクロールArduinoコード


次に、スクロールするテキストの例を見て、何が違うのかを見てみましょう。コードの下にその説明があります。

/*
      8x8 LED Matrix MAX7219 Scrolling Text Example

   Based on the following library:
   GitHub | riyas-org/max7219  https://github.com/riyas-org/max7219
*/


#include <MaxMatrix.h>
#include <avr/pgmspace.h>

PROGMEM const unsigned char CH[] = {
  3, 8, B00000000, B00000000, B00000000, B00000000, B00000000, // space
  1, 8, B01011111, B00000000, B00000000, B00000000, B00000000, // !
  3, 8, B00000011, B00000000, B00000011, B00000000, B00000000, // "
  5, 8, B00010100, B00111110, B00010100, B00111110, B00010100, // #
  4, 8, B00100100, B01101010, B00101011, B00010010, B00000000, // $
  5, 8, B01100011, B00010011, B00001000, B01100100, B01100011, // %
  5, 8, B00110110, B01001001, B01010110, B00100000, B01010000, // &
  1, 8, B00000011, B00000000, B00000000, B00000000, B00000000, // '
  3, 8, B00011100, B00100010, B01000001, B00000000, B00000000, // (
  3, 8, B01000001, B00100010, B00011100, B00000000, B00000000, // )
  5, 8, B00101000, B00011000, B00001110, B00011000, B00101000, // *
  5, 8, B00001000, B00001000, B00111110, B00001000, B00001000, // +
  2, 8, B10110000, B01110000, B00000000, B00000000, B00000000, // ,
  4, 8, B00001000, B00001000, B00001000, B00001000, B00000000, // -
  2, 8, B01100000, B01100000, B00000000, B00000000, B00000000, // .
  4, 8, B01100000, B00011000, B00000110, B00000001, B00000000, // /
  4, 8, B00111110, B01000001, B01000001, B00111110, B00000000, // 0
  3, 8, B01000010, B01111111, B01000000, B00000000, B00000000, // 1
  4, 8, B01100010, B01010001, B01001001, B01000110, B00000000, // 2
  4, 8, B00100010, B01000001, B01001001, B00110110, B00000000, // 3
  4, 8, B00011000, B00010100, B00010010, B01111111, B00000000, // 4
  4, 8, B00100111, B01000101, B01000101, B00111001, B00000000, // 5
  4, 8, B00111110, B01001001, B01001001, B00110000, B00000000, // 6
  4, 8, B01100001, B00010001, B00001001, B00000111, B00000000, // 7
  4, 8, B00110110, B01001001, B01001001, B00110110, B00000000, // 8
  4, 8, B00000110, B01001001, B01001001, B00111110, B00000000, // 9
  2, 8, B01010000, B00000000, B00000000, B00000000, B00000000, // :
  2, 8, B10000000, B01010000, B00000000, B00000000, B00000000, // ;
  3, 8, B00010000, B00101000, B01000100, B00000000, B00000000, // <
  3, 8, B00010100, B00010100, B00010100, B00000000, B00000000, // =
  3, 8, B01000100, B00101000, B00010000, B00000000, B00000000, // >
  4, 8, B00000010, B01011001, B00001001, B00000110, B00000000, // ?
  5, 8, B00111110, B01001001, B01010101, B01011101, B00001110, // @
  4, 8, B01111110, B00010001, B00010001, B01111110, B00000000, // A
  4, 8, B01111111, B01001001, B01001001, B00110110, B00000000, // B
  4, 8, B00111110, B01000001, B01000001, B00100010, B00000000, // C
  4, 8, B01111111, B01000001, B01000001, B00111110, B00000000, // D
  4, 8, B01111111, B01001001, B01001001, B01000001, B00000000, // E
  4, 8, B01111111, B00001001, B00001001, B00000001, B00000000, // F
  4, 8, B00111110, B01000001, B01001001, B01111010, B00000000, // G
  4, 8, B01111111, B00001000, B00001000, B01111111, B00000000, // H
  3, 8, B01000001, B01111111, B01000001, B00000000, B00000000, // I
  4, 8, B00110000, B01000000, B01000001, B00111111, B00000000, // J
  4, 8, B01111111, B00001000, B00010100, B01100011, B00000000, // K
  4, 8, B01111111, B01000000, B01000000, B01000000, B00000000, // L
  5, 8, B01111111, B00000010, B00001100, B00000010, B01111111, // M
  5, 8, B01111111, B00000100, B00001000, B00010000, B01111111, // N
  4, 8, B00111110, B01000001, B01000001, B00111110, B00000000, // O
  4, 8, B01111111, B00001001, B00001001, B00000110, B00000000, // P
  4, 8, B00111110, B01000001, B01000001, B10111110, B00000000, // Q
  4, 8, B01111111, B00001001, B00001001, B01110110, B00000000, // R
  4, 8, B01000110, B01001001, B01001001, B00110010, B00000000, // S
  5, 8, B00000001, B00000001, B01111111, B00000001, B00000001, // T
  4, 8, B00111111, B01000000, B01000000, B00111111, B00000000, // U
  5, 8, B00001111, B00110000, B01000000, B00110000, B00001111, // V
  5, 8, B00111111, B01000000, B00111000, B01000000, B00111111, // W
  5, 8, B01100011, B00010100, B00001000, B00010100, B01100011, // X
  5, 8, B00000111, B00001000, B01110000, B00001000, B00000111, // Y
  4, 8, B01100001, B01010001, B01001001, B01000111, B00000000, // Z
  2, 8, B01111111, B01000001, B00000000, B00000000, B00000000, // [
  4, 8, B00000001, B00000110, B00011000, B01100000, B00000000, // \ backslash
  2, 8, B01000001, B01111111, B00000000, B00000000, B00000000, // ]
  3, 8, B00000010, B00000001, B00000010, B00000000, B00000000, // hat
  4, 8, B01000000, B01000000, B01000000, B01000000, B00000000, // _
  2, 8, B00000001, B00000010, B00000000, B00000000, B00000000, // `
  4, 8, B00100000, B01010100, B01010100, B01111000, B00000000, // a
  4, 8, B01111111, B01000100, B01000100, B00111000, B00000000, // b
  4, 8, B00111000, B01000100, B01000100, B00101000, B00000000, // c
  4, 8, B00111000, B01000100, B01000100, B01111111, B00000000, // d
  4, 8, B00111000, B01010100, B01010100, B00011000, B00000000, // e
  3, 8, B00000100, B01111110, B00000101, B00000000, B00000000, // f
  4, 8, B10011000, B10100100, B10100100, B01111000, B00000000, // g
  4, 8, B01111111, B00000100, B00000100, B01111000, B00000000, // h
  3, 8, B01000100, B01111101, B01000000, B00000000, B00000000, // i
  4, 8, B01000000, B10000000, B10000100, B01111101, B00000000, // j
  4, 8, B01111111, B00010000, B00101000, B01000100, B00000000, // k
  3, 8, B01000001, B01111111, B01000000, B00000000, B00000000, // l
  5, 8, B01111100, B00000100, B01111100, B00000100, B01111000, // m
  4, 8, B01111100, B00000100, B00000100, B01111000, B00000000, // n
  4, 8, B00111000, B01000100, B01000100, B00111000, B00000000, // o
  4, 8, B11111100, B00100100, B00100100, B00011000, B00000000, // p
  4, 8, B00011000, B00100100, B00100100, B11111100, B00000000, // q
  4, 8, B01111100, B00001000, B00000100, B00000100, B00000000, // r
  4, 8, B01001000, B01010100, B01010100, B00100100, B00000000, // s
  3, 8, B00000100, B00111111, B01000100, B00000000, B00000000, // t
  4, 8, B00111100, B01000000, B01000000, B01111100, B00000000, // u
  5, 8, B00011100, B00100000, B01000000, B00100000, B00011100, // v
  5, 8, B00111100, B01000000, B00111100, B01000000, B00111100, // w
  5, 8, B01000100, B00101000, B00010000, B00101000, B01000100, // x
  4, 8, B10011100, B10100000, B10100000, B01111100, B00000000, // y
  3, 8, B01100100, B01010100, B01001100, B00000000, B00000000, // z
  3, 8, B00001000, B00110110, B01000001, B00000000, B00000000, // {
  1, 8, B01111111, B00000000, B00000000, B00000000, B00000000, // |
  3, 8, B01000001, B00110110, B00001000, B00000000, B00000000, // }
  4, 8, B00001000, B00000100, B00001000, B00000100, B00000000, // ~
};

int DIN = 7;   // DIN pin of MAX7219 module
int CLK = 6;   // CLK pin of MAX7219 module
int CS = 5;    // CS pin of MAX7219 module
int maxInUse = 2;

MaxMatrix m(DIN, CS, CLK, maxInUse);

byte buffer[10];

char text[]= "HowToMechatronics.com  "; // Scrolling text

void setup() {
  m.init(); // module initialize
  m.setIntensity(15); // dot matix intensity 0-15
}

void loop() {

  printStringWithShift(text, 100); // (text, scrolling speed)

}
// Display=the extracted characters with scrolling
void printCharWithShift(char c, int shift_speed) {
  if (c < 32) return;
  c -= 32;
  memcpy_P(buffer, CH + 7 * c, 7);
  m.writeSprite(32, 0, buffer);
  m.setColumn(32 + buffer[0], 0);

  for (int i = 0; i < buffer[0] + 1; i++)
  {
    delay(shift_speed);
    m.shiftLeft(false, false);
  }
}
// Extract the characters from the text string
void printStringWithShift(char* s, int shift_speed) {
  while (*s != 0) {
    printCharWithShift(*s, shift_speed);
    s++;
  }
}Code language: Arduino (arduino)

説明: ここでは、可変修飾子であり、SRAMの代わりにフラッシュメモリにデータを格納するために使用されるPROGMEN用の追加ライブラリを含める必要があります。この場合は文字や文字を定義するなど、静的な変数の大規模なデータベースがある場合、SRAMの2Kバイトと比較して32Kバイトとはるかに大きいため、フラッシュメモリに保存することをお勧めします。

>

次に、文字配列を使用してスクロールテキストを定義し、ループセクションでカスタム関数printStringWithShiftを使用して、2番目の引数でミリ秒単位で定義されたスクロール速度でスクロールテキストをLEDマトリックスに出力します。このカスタム関数が最初に行うことは、テキスト文字列から文字を抽出し、これらのスクロール文字をLEDマトリックスに表示することです。

Bluetooth経由で8×8LEDマトリックスを制御するためのAndroidアプリ


MAX7219がどのように機能するかを学んだら、3番目の例を作成できます。これは実用的なArduinoプロジェクトであり、Bluetooth通信を介してLEDマトリックスを制御するカスタムAndroidアプリを構築します。続行する前に、HC-05 Bluetoothモジュールの使用方法と、MITAppInventorオンラインアプリケーションを使用してカスタムAndroidアプリを構築する方法に関する詳細なチュートリアルを確認することをお勧めします。

これがArduinoコードで、前の例と比較した変更点を見てみましょう。

/*
      8x8 LED Matrix MAX7219 Scrolling Text
          Android Control via Bluetooth

   by Dejan Nedelkovski, www.HowToMechatronics.com

   Based on the following library:
   GitHub | riyas-org/max7219  https://github.com/riyas-org/max7219
*/

#include <MaxMatrix.h>
#include <SoftwareSerial.h>
#include <avr/pgmspace.h>

PROGMEM const unsigned char CH[] = {
  3, 8, B00000000, B00000000, B00000000, B00000000, B00000000, // space
  1, 8, B01011111, B00000000, B00000000, B00000000, B00000000, // !
  3, 8, B00000011, B00000000, B00000011, B00000000, B00000000, // "
  5, 8, B00010100, B00111110, B00010100, B00111110, B00010100, // #
  4, 8, B00100100, B01101010, B00101011, B00010010, B00000000, // $
  5, 8, B01100011, B00010011, B00001000, B01100100, B01100011, // %
  5, 8, B00110110, B01001001, B01010110, B00100000, B01010000, // &
  1, 8, B00000011, B00000000, B00000000, B00000000, B00000000, // '
  3, 8, B00011100, B00100010, B01000001, B00000000, B00000000, // (
  3, 8, B01000001, B00100010, B00011100, B00000000, B00000000, // )
  5, 8, B00101000, B00011000, B00001110, B00011000, B00101000, // *
  5, 8, B00001000, B00001000, B00111110, B00001000, B00001000, // +
  2, 8, B10110000, B01110000, B00000000, B00000000, B00000000, // ,
  4, 8, B00001000, B00001000, B00001000, B00001000, B00000000, // -
  2, 8, B01100000, B01100000, B00000000, B00000000, B00000000, // .
  4, 8, B01100000, B00011000, B00000110, B00000001, B00000000, // /
  4, 8, B00111110, B01000001, B01000001, B00111110, B00000000, // 0
  3, 8, B01000010, B01111111, B01000000, B00000000, B00000000, // 1
  4, 8, B01100010, B01010001, B01001001, B01000110, B00000000, // 2
  4, 8, B00100010, B01000001, B01001001, B00110110, B00000000, // 3
  4, 8, B00011000, B00010100, B00010010, B01111111, B00000000, // 4
  4, 8, B00100111, B01000101, B01000101, B00111001, B00000000, // 5
  4, 8, B00111110, B01001001, B01001001, B00110000, B00000000, // 6
  4, 8, B01100001, B00010001, B00001001, B00000111, B00000000, // 7
  4, 8, B00110110, B01001001, B01001001, B00110110, B00000000, // 8
  4, 8, B00000110, B01001001, B01001001, B00111110, B00000000, // 9
  2, 8, B01010000, B00000000, B00000000, B00000000, B00000000, // :
  2, 8, B10000000, B01010000, B00000000, B00000000, B00000000, // ;
  3, 8, B00010000, B00101000, B01000100, B00000000, B00000000, // <
  3, 8, B00010100, B00010100, B00010100, B00000000, B00000000, // =
  3, 8, B01000100, B00101000, B00010000, B00000000, B00000000, // >
  4, 8, B00000010, B01011001, B00001001, B00000110, B00000000, // ?
  5, 8, B00111110, B01001001, B01010101, B01011101, B00001110, // @
  4, 8, B01111110, B00010001, B00010001, B01111110, B00000000, // A
  4, 8, B01111111, B01001001, B01001001, B00110110, B00000000, // B
  4, 8, B00111110, B01000001, B01000001, B00100010, B00000000, // C
  4, 8, B01111111, B01000001, B01000001, B00111110, B00000000, // D
  4, 8, B01111111, B01001001, B01001001, B01000001, B00000000, // E
  4, 8, B01111111, B00001001, B00001001, B00000001, B00000000, // F
  4, 8, B00111110, B01000001, B01001001, B01111010, B00000000, // G
  4, 8, B01111111, B00001000, B00001000, B01111111, B00000000, // H
  3, 8, B01000001, B01111111, B01000001, B00000000, B00000000, // I
  4, 8, B00110000, B01000000, B01000001, B00111111, B00000000, // J
  4, 8, B01111111, B00001000, B00010100, B01100011, B00000000, // K
  4, 8, B01111111, B01000000, B01000000, B01000000, B00000000, // L
  5, 8, B01111111, B00000010, B00001100, B00000010, B01111111, // M
  5, 8, B01111111, B00000100, B00001000, B00010000, B01111111, // N
  4, 8, B00111110, B01000001, B01000001, B00111110, B00000000, // O
  4, 8, B01111111, B00001001, B00001001, B00000110, B00000000, // P
  4, 8, B00111110, B01000001, B01000001, B10111110, B00000000, // Q
  4, 8, B01111111, B00001001, B00001001, B01110110, B00000000, // R
  4, 8, B01000110, B01001001, B01001001, B00110010, B00000000, // S
  5, 8, B00000001, B00000001, B01111111, B00000001, B00000001, // T
  4, 8, B00111111, B01000000, B01000000, B00111111, B00000000, // U
  5, 8, B00001111, B00110000, B01000000, B00110000, B00001111, // V
  5, 8, B00111111, B01000000, B00111000, B01000000, B00111111, // W
  5, 8, B01100011, B00010100, B00001000, B00010100, B01100011, // X
  5, 8, B00000111, B00001000, B01110000, B00001000, B00000111, // Y
  4, 8, B01100001, B01010001, B01001001, B01000111, B00000000, // Z
  2, 8, B01111111, B01000001, B00000000, B00000000, B00000000, // [
  4, 8, B00000001, B00000110, B00011000, B01100000, B00000000, // \ backslash
  2, 8, B01000001, B01111111, B00000000, B00000000, B00000000, // ]
  3, 8, B00000010, B00000001, B00000010, B00000000, B00000000, // hat
  4, 8, B01000000, B01000000, B01000000, B01000000, B00000000, // _
  2, 8, B00000001, B00000010, B00000000, B00000000, B00000000, // `
  4, 8, B00100000, B01010100, B01010100, B01111000, B00000000, // a
  4, 8, B01111111, B01000100, B01000100, B00111000, B00000000, // b
  4, 8, B00111000, B01000100, B01000100, B00101000, B00000000, // c
  4, 8, B00111000, B01000100, B01000100, B01111111, B00000000, // d
  4, 8, B00111000, B01010100, B01010100, B00011000, B00000000, // e
  3, 8, B00000100, B01111110, B00000101, B00000000, B00000000, // f
  4, 8, B10011000, B10100100, B10100100, B01111000, B00000000, // g
  4, 8, B01111111, B00000100, B00000100, B01111000, B00000000, // h
  3, 8, B01000100, B01111101, B01000000, B00000000, B00000000, // i
  4, 8, B01000000, B10000000, B10000100, B01111101, B00000000, // j
  4, 8, B01111111, B00010000, B00101000, B01000100, B00000000, // k
  3, 8, B01000001, B01111111, B01000000, B00000000, B00000000, // l
  5, 8, B01111100, B00000100, B01111100, B00000100, B01111000, // m
  4, 8, B01111100, B00000100, B00000100, B01111000, B00000000, // n
  4, 8, B00111000, B01000100, B01000100, B00111000, B00000000, // o
  4, 8, B11111100, B00100100, B00100100, B00011000, B00000000, // p
  4, 8, B00011000, B00100100, B00100100, B11111100, B00000000, // q
  4, 8, B01111100, B00001000, B00000100, B00000100, B00000000, // r
  4, 8, B01001000, B01010100, B01010100, B00100100, B00000000, // s
  3, 8, B00000100, B00111111, B01000100, B00000000, B00000000, // t
  4, 8, B00111100, B01000000, B01000000, B01111100, B00000000, // u
  5, 8, B00011100, B00100000, B01000000, B00100000, B00011100, // v
  5, 8, B00111100, B01000000, B00111100, B01000000, B00111100, // w
  5, 8, B01000100, B00101000, B00010000, B00101000, B01000100, // x
  4, 8, B10011100, B10100000, B10100000, B01111100, B00000000, // y
  3, 8, B01100100, B01010100, B01001100, B00000000, B00000000, // z
  3, 8, B00001000, B00110110, B01000001, B00000000, B00000000, // {
  1, 8, B01111111, B00000000, B00000000, B00000000, B00000000, // |
  3, 8, B01000001, B00110110, B00001000, B00000000, B00000000, // }
  4, 8, B00001000, B00000100, B00001000, B00000100, B00000000, // ~
};

int dIn = 7;   // DIN pin of MAX7219 module
int clk = 6;   // CLK pin of MAX7219 module
int cs = 5;    // CS pin of MAX7219 module

int maxInUse = 2;    // Number of MAX7219's connected

MaxMatrix m(dIn, cs, clk, maxInUse);
SoftwareSerial Bluetooth(8, 7); // Bluetooth

byte buffer[10];
char incomebyte;
int scrollSpeed = 100;
char text[100] = "HowToMechatronics.com  "; // Initial text message
int brightness = 15;
int count = 0;
char indicator;

void setup() {
  m.init(); // MAX7219 initialization
  m.setIntensity(brightness); // initial led matrix intensity, 0-15
  Bluetooth.begin(38400); // Default communication rate of the Bluetooth module
}

void loop() {
  // Printing the text
  printStringWithShift(text, scrollSpeed);
  
  if (Bluetooth.available()) {   // Checks whether data is comming from the serial port
    indicator = Bluetooth.read();   // Starts reading the serial port, the first byte from the incoming data
    // If we have pressed the "Send" button from the Android App, clear the previous text
    if (indicator == '1') {
      for (int i = 0; i < 100; i++) {
        text[i] = 0;
        m.clear();
      }
      // Read the whole data/string comming from the phone and put it into text[] array.
      while (Bluetooth.available()) {
        incomebyte = Bluetooth.read();
        text[count] = incomebyte;
        count++;
      }
      count = 0;
    }
    // Adjusting the Scrolling Speed
    else if (indicator == '2') {
      String sS = Bluetooth.readString();
      scrollSpeed = 150 - sS.toInt(); // Milliseconds, subtraction because lower value means higher scrolling speed
    }
    // Adjusting the brightness
    else if (indicator == '3') {
      String sB = Bluetooth.readString();
      brightness = sB.toInt();
      m.setIntensity(brightness);
    }
  }

}

void printCharWithShift(char c, int shift_speed) {
  if (c < 32) return;
  c -= 32;
  memcpy_P(buffer, CH + 7 * c, 7);
  m.writeSprite(32, 0, buffer);
  m.setColumn(32 + buffer[0], 0);

  for (int i = 0; i < buffer[0] + 1; i++)
  {
    delay(shift_speed);
    m.shiftLeft(false, false);
  }
}

void printStringWithShift(char* s, int shift_speed) {
  while (*s != 0) {
    printCharWithShift(*s, shift_speed);
    s++;
  }
}

void printString(char* s)
{
  int col = 0;
  while (*s != 0)
  {
    if (*s < 32) continue;
    char c = *s - 32;
    memcpy_P(buffer, CH + 7 * c, 7);
    m.writeSprite(col, 0, buffer);
    m.setColumn(col + buffer[0], 0);
    col += buffer[0] + 1;
    s++;
  }
}Code language: Arduino (arduino)

説明: まず、Bluetooth通信を有効にし、プログラムに必要ないくつかの変数を定義するSoftwareSerial.hライブラリを含める必要があります。セットアップセクションでは、Bluetoothをデフォルトのボーレートである38400ビット/秒で初期化する必要があります。最初のテキストメッセージを「HowToMechatronics.com」に設定し、スクロール速度を100ミリ秒遅らせました。

次に、ループセクションで、Bluetooth.available()関数を使用して、シリアルポートからの着信データがあるかどうかを確認し、Bluetooth.read関数を使用してそれが当てはまる場合は、反復ごとに1バイトずつシリアルポートの読み取りを開始します。したがって、最初の着信バイトは常に「インジケータ」変数に格納され、それに応じて、テキストメッセージ、スクロール速度、またはLEDマトリックスの明るさを変更するかどうかを選択します。

Androidアプリのコードブロックを見ると、[送信]ボタンをクリックすると、最初に表示バイト(この場合は「1」)が送信されます。これは、テキストメッセージを変更する必要があることを意味します。そのために、Arduino側では、文字配列全体をクリアし、LEDマトリックス表示もクリアします。次に、「while」ループで、シリアルポートの残りのデータを読み取ります。これは、Androidアプリのテキストボックスに入力されたメッセージです。

表示変数が「2」の場合、スクロール速度スライダーの位置を変更したことを意味するため、Bluetooth.readString()関数を使用して新しい値を読み取り、スクロール速度を調整します。同様に、LEDの明るさを調整します。

ここからAndroidアプリをダウンロードできます:

AndrodApp for Arduino8x8LEDマトリックスコントロール

1ファイル 1.48MBダウンロード

AndrodApp forArduino8×8LEDマトリックスコントロール.aiaファイル

1ファイル 34.06KBダウンロード

このチュートリアルのほとんどすべてです。質問がある場合は、以下のコメントセクションを使用できます。


製造プロセス

  1. Arduinoでコインアクセプターを制御する
  2. MAX7219を搭載した24x16マトリックスのArduinoPongゲーム
  3. LEDを制御するBluetoothを搭載したArduino!
  4. CortanaでLEDを制御する
  5. ArduinoUnoでLEDマトリックスを制御する
  6. ArduinoUnoとBluetoothによる車の制御
  7. AndroidアプリでArduinoロボットアームを制御する
  8. スクロールテキストを使用したArduinoBluetooth制御マトリックス
  9. MAX72XXLEDマトリックスディスプレイ小惑星ゲーム
  10. Arduino / Android-BLUETOOTHマルチサーボモーター制御
  11. スネークLEDマトリックスゲーム