MAX7219 and HC-05
Control an MAX7219 with an HC-06 Bluetooth module and your mobile phone.
Components and supplies
1
Arduino UNO
1
HC-05 Bluetooth Module
Project description
Code
Code
arduino
MAX7219 &Hc 05
1 2#include <MaxMatrix.h> 3//an link for this Libery 4// https://code.google.com/archive/p/arudino-maxmatrix-library/ 5#include <avr/pgmspace.h> 6#include <SoftwareSerial.h> 7SoftwareSerial Blue(2, 3); 8 9PROGMEM const unsigned char CH[] = { 103, 8, B00000000, B00000000, B00000000, B00000000, B00000000, // space 111, 8, B01011111, B00000000, B00000000, B00000000, B00000000, // ! 123, 8, B00000011, B00000000, B00000011, B00000000, B00000000, // " 135, 8, B00010100, B00111110, B00010100, B00111110, B00010100, // # 144, 8, B00100100, B01101010, B00101011, B00010010, B00000000, // $ 155, 8, B01100011, B00010011, B00001000, B01100100, B01100011, // % 165, 8, B00110110, B01001001, B01010110, B00100000, B01010000, // & 171, 8, B00000011, B00000000, B00000000, B00000000, B00000000, // ' 183, 8, B00011100, B00100010, B01000001, B00000000, B00000000, // ( 193, 8, B01000001, B00100010, B00011100, B00000000, B00000000, // ) 205, 8, B00101000, B00011000, B00001110, B00011000, B00101000, // * 215, 8, B00001000, B00001000, B00111110, B00001000, B00001000, // + 222, 8, B10110000, B01110000, B00000000, B00000000, B00000000, // , 234, 8, B00001000, B00001000, B00001000, B00001000, B00000000, // - 242, 8, B01100000, B01100000, B00000000, B00000000, B00000000, // . 254, 8, B01100000, B00011000, B00000110, B00000001, B00000000, // / 264, 8, B00111110, B01000001, B01000001, B00111110, B00000000, // 0 273, 8, B01000010, B01111111, B01000000, B00000000, B00000000, // 1 284, 8, B01100010, B01010001, B01001001, B01000110, B00000000, // 2 294, 8, B00100010, B01000001, B01001001, B00110110, B00000000, // 3 304, 8, B00011000, B00010100, B00010010, B01111111, B00000000, // 4 314, 8, B00100111, B01000101, B01000101, B00111001, B00000000, // 5 324, 8, B00111110, B01001001, B01001001, B00110000, B00000000, // 6 334, 8, B01100001, B00010001, B00001001, B00000111, B00000000, // 7 344, 8, B00110110, B01001001, B01001001, B00110110, B00000000, // 8 354, 8, B00000110, B01001001, B01001001, B00111110, B00000000, // 9 362, 8, B01010000, B00000000, B00000000, B00000000, B00000000, // : 372, 8, B10000000, B01010000, B00000000, B00000000, B00000000, // ; 383, 8, B00010000, B00101000, B01000100, B00000000, B00000000, // < 393, 8, B00010100, B00010100, B00010100, B00000000, B00000000, // = 403, 8, B01000100, B00101000, B00010000, B00000000, B00000000, // > 414, 8, B00000010, B01011001, B00001001, B00000110, B00000000, // ? 425, 8, B00111110, B01001001, B01010101, B01011101, B00001110, // @ 434, 8, B01111110, B00010001, B00010001, B01111110, B00000000, // A 444, 8, B01111111, B01001001, B01001001, B00110110, B00000000, // B 454, 8, B00111110, B01000001, B01000001, B00100010, B00000000, // C 464, 8, B01111111, B01000001, B01000001, B00111110, B00000000, // D 474, 8, B01111111, B01001001, B01001001, B01000001, B00000000, // E 484, 8, B01111111, B00001001, B00001001, B00000001, B00000000, // F 494, 8, B00111110, B01000001, B01001001, B01111010, B00000000, // G 504, 8, B01111111, B00001000, B00001000, B01111111, B00000000, // H 513, 8, B01000001, B01111111, B01000001, B00000000, B00000000, // I 524, 8, B00110000, B01000000, B01000001, B00111111, B00000000, // J 534, 8, B01111111, B00001000, B00010100, B01100011, B00000000, // K 544, 8, B01111111, B01000000, B01000000, B01000000, B00000000, // L 555, 8, B01111111, B00000010, B00001100, B00000010, B01111111, // M 565, 8, B01111111, B00000100, B00001000, B00010000, B01111111, // N 574, 8, B00111110, B01000001, B01000001, B00111110, B00000000, // O 584, 8, B01111111, B00001001, B00001001, B00000110, B00000000, // P 594, 8, B00111110, B01000001, B01000001, B10111110, B00000000, // Q 604, 8, B01111111, B00001001, B00001001, B01110110, B00000000, // R 614, 8, B01000110, B01001001, B01001001, B00110010, B00000000, // S 625, 8, B00000001, B00000001, B01111111, B00000001, B00000001, // T 634, 8, B00111111, B01000000, B01000000, B00111111, B00000000, // U 645, 8, B00001111, B00110000, B01000000, B00110000, B00001111, // V 655, 8, B00111111, B01000000, B00111000, B01000000, B00111111, // W 665, 8, B01100011, B00010100, B00001000, B00010100, B01100011, // X 675, 8, B00000111, B00001000, B01110000, B00001000, B00000111, // Y 684, 8, B01100001, B01010001, B01001001, B01000111, B00000000, // Z 692, 8, B01111111, B01000001, B00000000, B00000000, B00000000, // [ 704, 8, B00000001, B00000110, B00011000, B01100000, B00000000, // \backslash 712, 8, B01000001, B01111111, B00000000, B00000000, B00000000, // ] 723, 8, B00000010, B00000001, B00000010, B00000000, B00000000, // hat 734, 8, B01000000, B01000000, B01000000, B01000000, B00000000, // _ 742, 8, B00000001, B00000010, B00000000, B00000000, B00000000, // ` 754, 8, B00100000, B01010100, B01010100, B01111000, B00000000, // a 764, 8, B01111111, B01000100, B01000100, B00111000, B00000000, // b 774, 8, B00111000, B01000100, B01000100, B00101000, B00000000, // c 784, 8, B00111000, B01000100, B01000100, B01111111, B00000000, // d 794, 8, B00111000, B01010100, B01010100, B00011000, B00000000, // e 803, 8, B00000100, B01111110, B00000101, B00000000, B00000000, // f 814, 8, B10011000, B10100100, B10100100, B01111000, B00000000, // g 824, 8, B01111111, B00000100, B00000100, B01111000, B00000000, // h 833, 8, B01000100, B01111101, B01000000, B00000000, B00000000, // i 844, 8, B01000000, B10000000, B10000100, B01111101, B00000000, // j 854, 8, B01111111, B00010000, B00101000, B01000100, B00000000, // k 863, 8, B01000001, B01111111, B01000000, B00000000, B00000000, // l 875, 8, B01111100, B00000100, B01111100, B00000100, B01111000, // m 884, 8, B01111100, B00000100, B00000100, B01111000, B00000000, // n 894, 8, B00111000, B01000100, B01000100, B00111000, B00000000, // o 904, 8, B11111100, B00100100, B00100100, B00011000, B00000000, // p 914, 8, B00011000, B00100100, B00100100, B11111100, B00000000, // q 924, 8, B01111100, B00001000, B00000100, B00000100, B00000000, // r 934, 8, B01001000, B01010100, B01010100, B00100100, B00000000, // s 943, 8, B00000100, B00111111, B01000100, B00000000, B00000000, // t 954, 8, B00111100, B01000000, B01000000, B01111100, B00000000, // u 965, 8, B00011100, B00100000, B01000000, B00100000, B00011100, // v 975, 8, B00111100, B01000000, B00111100, B01000000, B00111100, // w 985, 8, B01000100, B00101000, B00010000, B00101000, B01000100, // x 994, 8, B10011100, B10100000, B10100000, B01111100, B00000000, // y 1003, 8, B01100100, B01010100, B01001100, B00000000, B00000000, // z 1013, 8, B00001000, B00110110, B01000001, B00000000, B00000000, // { 1021, 8, B01111111, B00000000, B00000000, B00000000, B00000000, // | 1033, 8, B01000001, B00110110, B00001000, B00000000, B00000000, // } 1044, 8, B00001000, B00000100, B00001000, B00000100, B00000000, // ~ 105}; 106 107int data = 12; // 8, DIN pin of MAX7219 module 108int load = 11; // 9, CS pin of MAX7219 module 109int clock = 10; // 10, CLK pin of MAX7219 module 110 111int maxInUse = 3; //change this variable to set how many MAX7219's you'll use 112 113MaxMatrix m(data, load, clock, maxInUse); // define module 114 115byte buffer[10]; 116 117// active sentenses 118char string1[] = " WELCOME TO ELECTRONIC CLINIC "; 119 120// just for tests 121char string7[] = " A B C D E F G H I J K L M N O P Q R S T U V X W Y Z "; 122char string8[] = " a b c d e f g h i j k l m n o p q r s t u v x w y z "; 123char string9[] = " 1 2 3 4 5 6 7 8 9 0 - = "; 124char string10[] = " ! @ # $ % & * ( ) _ + "; 125char string11[] = " ' , . ; ~ ] [ | < > : ^ } ` { / ? "; 126 127char string12[] = " Hello ! "; 128 129int bactive = 0 ; //bluetooth active 130int bdactive=0; // bluetooth deactive 131char bluetooth[20]; 132char c; 133 134 135void setup(){ 136 m.init(); // module initialize 137 m.setIntensity(15); // dot matix intensity 0-15 138 Serial.begin(9600); // serial communication initialize 139 Blue.begin(9600); 140} 141 142void loop(){ 143 144 145 146 // this is the code if you want to entering a message via serial console 147 if (Blue.available() > 0) 148{ 149 c = Blue.read(); 150 // Serial.println(c); 151 printCharWithShift(c, 100); 152 bluetooth[20] += c; 153 } 154 155 if (Serial.available() > 0) 156{ 157 c = Serial.read(); 158 // Serial.println(c); 159 printCharWithShift(c, 100); 160 bluetooth[20] += c; 161 } 162 163 delay(100); 164 m.shiftLeft(false, true); 165 166 167 // 1st block - print the active sentences 168 // comment this block when using the 2nd messages block 169 170 171 //printStringWithShift(string1, 100); 172 //printStringWithShift(string2, 100); 173 //printStringWithShift(string3, 100); 174 //printStringWithShift(string4, 100); 175 //printStringWithShift(string5, 100); 176 //printStringWithShift(string6, 100); 177 178 // 2nd block - print sentences just for tests 179 // uncomment this block to use it 180 /* 181 printStringWithShift(string7, 100); 182 printStringWithShift(string8, 100); 183 printStringWithShift(string9, 100); 184 printStringWithShift(string10, 100); 185 printStringWithShift(string11, 100); 186 */ 187} 188 189void printCharWithShift(char c, int shift_speed){ 190 if (c < 32) return; 191 c -= 32; 192 memcpy_P(buffer, CH + 7*c, 7); 193 m.writeSprite(maxInUse*8, 0, buffer); 194 m.setColumn(maxInUse*8 + buffer[0], 0); 195 196 for (int i=0; i<buffer[0]+1; i++) 197 { 198 delay(shift_speed); 199 m.shiftLeft(false, false); 200 } 201} 202 203void printStringWithShift(char* s, int shift_speed){ 204 while (*s != 0){ 205 printCharWithShift(*s, shift_speed); 206 s++; 207 } 208} 209 210void printString(char* s) 211{ 212 int col = 0; 213 while (*s != 0) 214 { 215 if (*s < 32) continue; 216 char c = *s - 32; 217 memcpy_P(buffer, CH + 7*c, 7); 218 m.writeSprite(col, 0, buffer); 219 m.setColumn(col + buffer[0], 0); 220 col += buffer[0] + 1; 221 s++; 222 } 223} 224
Code
arduino
MAX7219 &Hc 05
1 2#include <MaxMatrix.h> 3//an link for this Libery 4// https://code.google.com/archive/p/arudino-maxmatrix-library/ 5#include <avr/pgmspace.h> 6#include <SoftwareSerial.h> 7SoftwareSerial Blue(2, 3); 8 9PROGMEM const unsigned char CH[] = { 103, 8, B00000000, B00000000, B00000000, B00000000, B00000000, // space 111, 8, B01011111, B00000000, B00000000, B00000000, B00000000, // ! 123, 8, B00000011, B00000000, B00000011, B00000000, B00000000, // " 135, 8, B00010100, B00111110, B00010100, B00111110, B00010100, // # 144, 8, B00100100, B01101010, B00101011, B00010010, B00000000, // $ 155, 8, B01100011, B00010011, B00001000, B01100100, B01100011, // % 165, 8, B00110110, B01001001, B01010110, B00100000, B01010000, // & 171, 8, B00000011, B00000000, B00000000, B00000000, B00000000, // ' 183, 8, B00011100, B00100010, B01000001, B00000000, B00000000, // ( 193, 8, B01000001, B00100010, B00011100, B00000000, B00000000, // ) 205, 8, B00101000, B00011000, B00001110, B00011000, B00101000, // * 215, 8, B00001000, B00001000, B00111110, B00001000, B00001000, // + 222, 8, B10110000, B01110000, B00000000, B00000000, B00000000, // , 234, 8, B00001000, B00001000, B00001000, B00001000, B00000000, // - 242, 8, B01100000, B01100000, B00000000, B00000000, B00000000, // . 254, 8, B01100000, B00011000, B00000110, B00000001, B00000000, // / 264, 8, B00111110, B01000001, B01000001, B00111110, B00000000, // 0 273, 8, B01000010, B01111111, B01000000, B00000000, B00000000, // 1 284, 8, B01100010, B01010001, B01001001, B01000110, B00000000, // 2 294, 8, B00100010, B01000001, B01001001, B00110110, B00000000, // 3 304, 8, B00011000, B00010100, B00010010, B01111111, B00000000, // 4 314, 8, B00100111, B01000101, B01000101, B00111001, B00000000, // 5 324, 8, B00111110, B01001001, B01001001, B00110000, B00000000, // 6 334, 8, B01100001, B00010001, B00001001, B00000111, B00000000, // 7 344, 8, B00110110, B01001001, B01001001, B00110110, B00000000, // 8 354, 8, B00000110, B01001001, B01001001, B00111110, B00000000, // 9 362, 8, B01010000, B00000000, B00000000, B00000000, B00000000, // : 372, 8, B10000000, B01010000, B00000000, B00000000, B00000000, // ; 383, 8, B00010000, B00101000, B01000100, B00000000, B00000000, // < 393, 8, B00010100, B00010100, B00010100, B00000000, B00000000, // = 403, 8, B01000100, B00101000, B00010000, B00000000, B00000000, // > 414, 8, B00000010, B01011001, B00001001, B00000110, B00000000, // ? 425, 8, B00111110, B01001001, B01010101, B01011101, B00001110, // @ 434, 8, B01111110, B00010001, B00010001, B01111110, B00000000, // A 444, 8, B01111111, B01001001, B01001001, B00110110, B00000000, // B 454, 8, B00111110, B01000001, B01000001, B00100010, B00000000, // C 464, 8, B01111111, B01000001, B01000001, B00111110, B00000000, // D 474, 8, B01111111, B01001001, B01001001, B01000001, B00000000, // E 484, 8, B01111111, B00001001, B00001001, B00000001, B00000000, // F 494, 8, B00111110, B01000001, B01001001, B01111010, B00000000, // G 504, 8, B01111111, B00001000, B00001000, B01111111, B00000000, // H 513, 8, B01000001, B01111111, B01000001, B00000000, B00000000, // I 524, 8, B00110000, B01000000, B01000001, B00111111, B00000000, // J 534, 8, B01111111, B00001000, B00010100, B01100011, B00000000, // K 544, 8, B01111111, B01000000, B01000000, B01000000, B00000000, // L 555, 8, B01111111, B00000010, B00001100, B00000010, B01111111, // M 565, 8, B01111111, B00000100, B00001000, B00010000, B01111111, // N 574, 8, B00111110, B01000001, B01000001, B00111110, B00000000, // O 584, 8, B01111111, B00001001, B00001001, B00000110, B00000000, // P 594, 8, B00111110, B01000001, B01000001, B10111110, B00000000, // Q 604, 8, B01111111, B00001001, B00001001, B01110110, B00000000, // R 614, 8, B01000110, B01001001, B01001001, B00110010, B00000000, // S 625, 8, B00000001, B00000001, B01111111, B00000001, B00000001, // T 634, 8, B00111111, B01000000, B01000000, B00111111, B00000000, // U 645, 8, B00001111, B00110000, B01000000, B00110000, B00001111, // V 655, 8, B00111111, B01000000, B00111000, B01000000, B00111111, // W 665, 8, B01100011, B00010100, B00001000, B00010100, B01100011, // X 675, 8, B00000111, B00001000, B01110000, B00001000, B00000111, // Y 684, 8, B01100001, B01010001, B01001001, B01000111, B00000000, // Z 692, 8, B01111111, B01000001, B00000000, B00000000, B00000000, // [ 704, 8, B00000001, B00000110, B00011000, B01100000, B00000000, // \backslash 712, 8, B01000001, B01111111, B00000000, B00000000, B00000000, // ] 723, 8, B00000010, B00000001, B00000010, B00000000, B00000000, // hat 734, 8, B01000000, B01000000, B01000000, B01000000, B00000000, // _ 742, 8, B00000001, B00000010, B00000000, B00000000, B00000000, // ` 754, 8, B00100000, B01010100, B01010100, B01111000, B00000000, // a 764, 8, B01111111, B01000100, B01000100, B00111000, B00000000, // b 774, 8, B00111000, B01000100, B01000100, B00101000, B00000000, // c 784, 8, B00111000, B01000100, B01000100, B01111111, B00000000, // d 794, 8, B00111000, B01010100, B01010100, B00011000, B00000000, // e 803, 8, B00000100, B01111110, B00000101, B00000000, B00000000, // f 814, 8, B10011000, B10100100, B10100100, B01111000, B00000000, // g 824, 8, B01111111, B00000100, B00000100, B01111000, B00000000, // h 833, 8, B01000100, B01111101, B01000000, B00000000, B00000000, // i 844, 8, B01000000, B10000000, B10000100, B01111101, B00000000, // j 854, 8, B01111111, B00010000, B00101000, B01000100, B00000000, // k 863, 8, B01000001, B01111111, B01000000, B00000000, B00000000, // l 875, 8, B01111100, B00000100, B01111100, B00000100, B01111000, // m 884, 8, B01111100, B00000100, B00000100, B01111000, B00000000, // n 894, 8, B00111000, B01000100, B01000100, B00111000, B00000000, // o 904, 8, B11111100, B00100100, B00100100, B00011000, B00000000, // p 914, 8, B00011000, B00100100, B00100100, B11111100, B00000000, // q 924, 8, B01111100, B00001000, B00000100, B00000100, B00000000, // r 934, 8, B01001000, B01010100, B01010100, B00100100, B00000000, // s 943, 8, B00000100, B00111111, B01000100, B00000000, B00000000, // t 954, 8, B00111100, B01000000, B01000000, B01111100, B00000000, // u 965, 8, B00011100, B00100000, B01000000, B00100000, B00011100, // v 975, 8, B00111100, B01000000, B00111100, B01000000, B00111100, // w 985, 8, B01000100, B00101000, B00010000, B00101000, B01000100, // x 994, 8, B10011100, B10100000, B10100000, B01111100, B00000000, // y 1003, 8, B01100100, B01010100, B01001100, B00000000, B00000000, // z 1013, 8, B00001000, B00110110, B01000001, B00000000, B00000000, // { 1021, 8, B01111111, B00000000, B00000000, B00000000, B00000000, // | 1033, 8, B01000001, B00110110, B00001000, B00000000, B00000000, // } 1044, 8, B00001000, B00000100, B00001000, B00000100, B00000000, // ~ 105}; 106 107int data = 12; // 8, DIN pin of MAX7219 module 108int load = 11; // 9, CS pin of MAX7219 module 109int clock = 10; // 10, CLK pin of MAX7219 module 110 111int maxInUse = 3; //change this variable to set how many MAX7219's you'll use 112 113MaxMatrix m(data, load, clock, maxInUse); // define module 114 115byte buffer[10]; 116 117// active sentenses 118char string1[] = " WELCOME TO ELECTRONIC CLINIC "; 119 120// just for tests 121char string7[] = " A B C D E F G H I J K L M N O P Q R S T U V X W Y Z "; 122char string8[] = " a b c d e f g h i j k l m n o p q r s t u v x w y z "; 123char string9[] = " 1 2 3 4 5 6 7 8 9 0 - = "; 124char string10[] = " ! @ # $ % & * ( ) _ + "; 125char string11[] = " ' , . ; ~ ] [ | < > : ^ } ` { / ? "; 126 127char string12[] = " Hello ! "; 128 129int bactive = 0 ; //bluetooth active 130int bdactive=0; // bluetooth deactive 131char bluetooth[20]; 132char c; 133 134 135void setup(){ 136 m.init(); // module initialize 137 m.setIntensity(15); // dot matix intensity 0-15 138 Serial.begin(9600); // serial communication initialize 139 Blue.begin(9600); 140} 141 142void loop(){ 143 144 145 146 // this is the code if you want to entering a message via serial console 147 if (Blue.available() > 0) 148{ 149 c = Blue.read(); 150 // Serial.println(c); 151 printCharWithShift(c, 100); 152 bluetooth[20] += c; 153 } 154 155 if (Serial.available() > 0) 156{ 157 c = Serial.read(); 158 // Serial.println(c); 159 printCharWithShift(c, 100); 160 bluetooth[20] += c; 161 } 162 163 delay(100); 164 m.shiftLeft(false, true); 165 166 167 // 1st block - print the active sentences 168 // comment this block when using the 2nd messages block 169 170 171 //printStringWithShift(string1, 100); 172 //printStringWithShift(string2, 100); 173 //printStringWithShift(string3, 100); 174 //printStringWithShift(string4, 100); 175 //printStringWithShift(string5, 100); 176 //printStringWithShift(string6, 100); 177 178 // 2nd block - print sentences just for tests 179 // uncomment this block to use it 180 /* 181 printStringWithShift(string7, 100); 182 printStringWithShift(string8, 100); 183 printStringWithShift(string9, 100); 184 printStringWithShift(string10, 100); 185 printStringWithShift(string11, 100); 186 */ 187} 188 189void printCharWithShift(char c, int shift_speed){ 190 if (c < 32) return; 191 c -= 32; 192 memcpy_P(buffer, CH + 7*c, 7); 193 m.writeSprite(maxInUse*8, 0, buffer); 194 m.setColumn(maxInUse*8 + buffer[0], 0); 195 196 for (int i=0; i<buffer[0]+1; i++) 197 { 198 delay(shift_speed); 199 m.shiftLeft(false, false); 200 } 201} 202 203void printStringWithShift(char* s, int shift_speed){ 204 while (*s != 0){ 205 printCharWithShift(*s, shift_speed); 206 s++; 207 } 208} 209 210void printString(char* s) 211{ 212 int col = 0; 213 while (*s != 0) 214 { 215 if (*s < 32) continue; 216 char c = *s - 32; 217 memcpy_P(buffer, CH + 7*c, 7); 218 m.writeSprite(col, 0, buffer); 219 m.setColumn(col + buffer[0], 0); 220 col += buffer[0] + 1; 221 s++; 222 } 223} 224
Downloadable files
Tutorial
How it is building
Tutorial

Comments
Only logged in users can leave comments