Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define COL_NUM 16 // number of columns (16)
- #define SPEED 20
- #define LATCH 2
- #define CLOCK_ROW 3
- #define DATA_ROW 4
- #define CLOCK_COL 5
- #define DATA_COL 6
- unsigned char charMatrix[26][8] = {
- {0b00111111, 0b01010000, 0b10010000, 0b01010000, 0b00111111, 0b00000000, 0b00000000, 0b00000000},//A
- {0b11111111, 0b10010001, 0b10010001, 0b10010001, 0b01101110, 0b00000000, 0b00000000, 0b00000000},//B
- {0b01111110, 0b10000001, 0b10000001, 0b10000001, 0b10000001, 0b00000000, 0b00000000, 0b00000000},//C
- {0b11111111, 0b10000001, 0b10000001, 0b10000001, 0b01111110, 0b00000000, 0b00000000, 0b00000000},//D
- {0b11111111, 0b10010001, 0b10010001, 0b10010001, 0b10010001, 0b00000000, 0b00000000, 0b00000000},//E
- {0b11111111, 0b10010000, 0b10010000, 0b10010000, 0b10010000, 0b00000000, 0b00000000, 0b00000000},//F
- {0b01111110, 0b10000001, 0b10000001, 0b10001001, 0b01001110, 0b00001000, 0b00000000, 0b00000000},//G
- {0b11111111, 0b00010000, 0b00010000, 0b00010000, 0b11111111, 0b00000000, 0b00000000, 0b00000000},//H
- {0b10000001, 0b10000001, 0b11111111, 0b10000001, 0b10000001, 0b00000000, 0b00000000, 0b00000000},//I
- {0b10000011, 0b10000001, 0b11111111, 0b10000000, 0b10000000, 0b00000000, 0b00000000, 0b00000000},//J
- {0b11111111, 0b00011000, 0b00100100, 0b01000010, 0b10000001, 0b00000000, 0b00000000, 0b00000000},//K
- {0b11111111, 0b00000001, 0b00000001, 0b00000001, 0b00000001, 0b00000000, 0b00000000, 0b00000000},//L
- {0b11111111, 0b01000000, 0b00100000, 0b01000000, 0b11111111, 0b00000000, 0b00000000, 0b00000000},//M
- {0b11111111, 0b01000000, 0b00100000, 0b00010000, 0b11111111, 0b00000000, 0b00000000, 0b00000000},//N
- {0b01111110, 0b10000001, 0b10000001, 0b10000001, 0b01111110, 0b00000000, 0b00000000, 0b00000000},//O
- {0b11111111, 0b10010000, 0b10010000, 0b10010000, 0b01100000, 0b00000000, 0b00000000, 0b00000000},//P
- {0b01111110, 0b10000001, 0b10000001, 0b10000101, 0b01111110, 0b00000001, 0b00000000, 0b00000000},//Q
- {0b11111111, 0b10011000, 0b10010100, 0b10010010, 0b01100001, 0b00000000, 0b00000000, 0b00000000},//R
- {0b01100001, 0b10010001, 0b10010001, 0b10010001, 0b01001110, 0b00000000, 0b00000000, 0b00000000},//S
- {0b10000000, 0b10000000, 0b11111111, 0b10000000, 0b10000000, 0b00000000, 0b00000000, 0b00000000},//T
- {0b11111110, 0b00000001, 0b00000001, 0b00000001, 0b11111110, 0b00000000, 0b00000000, 0b00000000},//U
- {0b11111100, 0b00000010, 0b00000001, 0b00000010, 0b11111100, 0b00000000, 0b00000000, 0b00000000},//V
- {0b11111111, 0b00000010, 0b00000100, 0b00000010, 0b11111111, 0b00000000, 0b00000000, 0b00000000},//W
- {0b11000011, 0b00100100, 0b00011000, 0b00100100, 0b11000011, 0b00000000, 0b00000000, 0b00000000},//X
- {0b11100000, 0b00010000, 0b00001111, 0b00010000, 0b11100000, 0b00000000, 0b00000000, 0b00000000},//Y
- {0b10000111, 0b10001001, 0b10010001, 0b10100001, 0b11000001, 0b00000000, 0b00000000, 0b00000000} //Z
- };
- unsigned char numMatrix[10][8] = {
- {0b01111110, 0b10000001, 0b10000001, 0b10000001, 0b01111110, 0b00000000, 0b00000000, 0b00000000},//0
- {0b00100001, 0b01000001, 0b11111111, 0b00000001, 0b00000001, 0b00000000, 0b00000000, 0b00000000},//1
- {0b01000011, 0b10000101, 0b10001001, 0b10010001, 0b01100001, 0b00000000, 0b00000000, 0b00000000},//2
- {0b01000001, 0b10010001, 0b10010001, 0b10010001, 0b01101110, 0b00000000, 0b00000000, 0b00000000},//3
- {0b11110000, 0b00010000, 0b00010000, 0b11111111, 0b00000000, 0b00000000, 0b00000000, 0b00000000},//4
- {0b11110001, 0b10010001, 0b10010001, 0b10010001, 0b10001110, 0b00000000, 0b00000000, 0b00000000},//5
- {0b01111110, 0b10010001, 0b10010001, 0b10010001, 0b10001110, 0b00000000, 0b00000000, 0b00000000},//6
- {0b10000000, 0b10000000, 0b10011111, 0b10100000, 0b11000000, 0b00000000, 0b00000000, 0b00000000},//7
- {0b01101110, 0b10010001, 0b10010001, 0b10010001, 0b01101110, 0b00000000, 0b00000000, 0b00000000},//8
- {0b01100000, 0b10010001, 0b10010001, 0b10010001, 0b01111110, 0b00000000, 0b00000000, 0b00000000} //9
- };
- unsigned char specialMatrix[5][8] = {
- {0b00011000, 0b00100100, 0b01000010, 0b00100001, 0b01000010, 0b00100100, 0b00011000, 0b00000000},// HEART
- {0b00000001, 0b00000110, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000},// ,
- {0b00000001, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000},// .
- {0b11111101, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000} // !
- };
- unsigned char buffer[COL_NUM];
- //Tìm xem một kí tự ứng với đâu trong các mảng UP, NUM, SPECIALS)
- unsigned char* getArrFromChar(unsigned char ch) {
- if ((ch >= 48) && (ch <= 57)) // Numbers
- return numMatrix[ch - 48];
- if ((ch>= 65) && (ch <= 90)) // Characters
- return charMatrix[ch - 65];
- switch (ch) { // Specials
- case '$': // Heart
- return specialMatrix[0];
- case ',':
- return specialMatrix[1];
- case '.':
- return specialMatrix[2];
- case '!':
- return specialMatrix[3];
- };
- return NULL; // if nothing matches
- }
- void moveLeft() {
- // &buffer[1] because buffer[1] is *(buffer+1), and we need a pointer
- memmove(buffer, &(buffer[1]), (COL_NUM - 1));
- }
- void show(unsigned char hold) {
- for (unsigned char k = 0; k < hold; k++) {
- for (unsigned char row = 0; row < 8; row++) {
- unsigned char d[2] = {0, 0};
- for (unsigned char col = 0; col < COL_NUM; col++) {
- d[col/8] = (d[col/8] | ((buffer[col] >> (7-row)) & 1));
- if (col%8!=7)
- d[col/8]<<=1;
- }
- // Turn off
- digitalWrite(LATCH, LOW);
- // We are printing to row {{row}}
- shiftOut(DATA_ROW, CLOCK_ROW, MSBFIRST, ~(_BV(row)));
- //Serial.print(d[1], BIN);
- //Serial.println(d[0], BIN);
- // Hmm which is the right order then
- shiftOut(DATA_COL, CLOCK_COL, LSBFIRST, d[1]);
- shiftOut(DATA_COL, CLOCK_COL, LSBFIRST, d[0]);
- // Turn on
- digitalWrite(LATCH, HIGH);
- //delay(5000);
- }
- }
- }
- void addCol(unsigned char col) {
- moveLeft();
- buffer[COL_NUM - 1] = col;
- show(SPEED);
- }
- //Thêm một kí tự, sau đó gọi hàm addCol để hiển thị từng phần của kí tự
- void addChar(char chr) {
- unsigned char* arr = getArrFromChar(chr);
- if (arr == NULL)
- return;
- for (unsigned char i = 0; i < 8; i++) {
- if (arr[i] != 0) { // nice trick there m8
- addCol(arr[i]);
- }
- }
- addCol(0);
- }
- //Thêm vào một cột vào mảng leds để hiển thị
- // Move everything to the left
- //Hiển thị mảng leds ra ma trận
- void parseString(const char* s) {
- while (*s) {
- if (*s == ' ') {
- addCol(0);
- addCol(0);
- } else {
- addChar(toupper(*s));
- }
- s++;
- }
- }
- void setup() {
- Serial.begin(9600);
- pinMode(LATCH, OUTPUT);
- pinMode(CLOCK_COL, OUTPUT);
- pinMode(DATA_COL, OUTPUT);
- pinMode(CLOCK_ROW, OUTPUT);
- pinMode(DATA_ROW, OUTPUT);
- }
- void loop() {
- parseString("DANG XUAN MINH SON ");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement