当前位置:首页 > 科学研究 > 电子编程 > 正文内容

Arduino Project 021 - LED Dot Matrix Display - Scrolling Message

RonWang2个月前 (10-08)电子编程94

There are many different ways to drive LEDs. Using shift registers is one way and they have their advantages. However, there are lots of ICs available that are specifically designed to drive LED displays and make life a lot easier for you. One of the most popular LED Driver ICs in the Arduino community is the MAX7219 serial interfaced, 8-digit LED Display Driver chips made by Maxim. These chips are designed to control 7-segment numeric LED displays of up to 8 digits, bar graph displays, or 88 LED dot matrix displays, which is what you will be using them for. The Arduino IDE comes with a library called Matrix plus some example code that was specifically written for the MAX7219 chips. Using this library will make using these chips a breeze. However, in this project you are not going to use any external libraries. Instead, you are going to do things the hard way and write every piece of code yourself. That way, you will learn exactly how the MAX7219 chip works, and you can transfer these skills to utilizing any other LED driver chip you wish.

You will need a MAX7219 LED Driver IC. Alternatively, you can use an Austria Microsystems AS1107, which is pretty much identical to the MAX7219 and will work with no changes to your code or circuit. The 88 dot matrix display needs to be of the Common Cathode variety this time as the MAX chip will not work with a Common Anode display.

Project 21 – LED Dot Matrix Display – Scrolling Message

/* Coding Ron Wang
   Oct.8th 2024
   Autaba support for coding hardware
   Project 21 LED Dot Matrix – Scrolling Message
 */
 
#include <avr/pgmspace.h>
#include <TimerOne.h>
int DataPin = 11; // Pin 11 on MAX  / DIN
int ClockPin = 12; //Pin 12 on MAX / CLK
int LoadPin = 8; // Pin 8 on MAX / CS

byte buffer[8]; 
const byte font[][8] PROGMEM = {
//The printable ASCII characters only (32-126)
{B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000},
{B00000100, B00000100, B00000100, B00000100, B00000100, B00000100, B00000000, B00000100},
{B00001010, B00001010, B00001010, B00000000, B00000000, B00000000, B00000000, B00000000},
{B00000000, B00001010, B00011111, B00001010, B00011111, B00001010, B00011111, B00001010},
{B00000111, B00001100, B00010100, B00001100, B00000110, B00000101, B00000110, B00011100},
{B00011001, B00011010, B00000010, B00000100, B00000100, B00001000, B00001011, B00010011},
{B00000110, B00001010, B00010010, B00010100, B00001001, B00010110, B00010110, B00001001},
{B00000100, B00000100, B00000100, B00000000, B00000000, B00000000, B00000000, B00000000},
{B00000010, B00000100, B00001000, B00001000, B00001000, B00001000, B00000100, B00000010},
{B00001000, B00000100, B00000010, B00000010, B00000010, B00000010, B00000100, B00001000},
{B00010101, B00001110, B00011111, B00001110, B00010101, B00000000, B00000000, B00000000},
{B00000000, B00000000, B00000100, B00000100, B00011111, B00000100, B00000100, B00000000},
{B00000000, B00000000, B00000000, B00000000, B00000000, B00000110, B00000100, B00001000},
{B00000000, B00000000, B00000000, B00000000, B00001110, B00000000, B00000000, B00000000},
{B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000100},
{B00000001, B00000010, B00000010, B00000100, B00000100, B00001000, B00001000, B00010000},
{B00001110, B00010001, B00010011, B00010001, B00010101, B00010001, B00011001, B00001110},
{B00000100, B00001100, B00010100, B00000100, B00000100, B00000100, B00000100, B00011111},
{B00001110, B00010001, B00010001, B00000010, B00000100, B00001000, B00010000, B00011111},
{B00001110, B00010001, B00000001, B00001110, B00000001, B00000001, B00010001, B00001110},
{B00010000, B00010000, B00010100, B00010100, B00011111, B00000100, B00000100, B00000100},
{B00011111, B00010000, B00010000, B00011110, B00000001, B00000001, B00000001, B00011110},
{B00000111, B00001000, B00010000, B00011110, B00010001, B00010001, B00010001, B00001110},
{B00011111, B00000001, B00000001, B00000001, B00000010, B00000100, B00001000, B00010000},
{B00001110, B00010001, B00010001, B00001110, B00010001, B00010001, B00010001, B00001110},
{B00001110, B00010001, B00010001, B00001111, B00000001, B00000001, B00000001, B00000001},
{B00000000, B00000100, B00000100, B00000000, B00000000, B00000100, B00000100, B00000000},
{B00000000, B00000100, B00000100, B00000000, B00000000, B00000100, B00000100, B00001000},
{B00000001, B00000010, B00000100, B00001000, B00001000, B00000100, B00000010, B00000001},
{B00000000, B00000000, B00000000, B00011110, B00000000, B00011110, B00000000, B00000000},
{B00010000, B00001000, B00000100, B00000010, B00000010, B00000100, B00001000, B00010000},
{B00001110, B00010001, B00010001, B00000010, B00000100, B00000100, B00000000, B00000100},
{B00001110, B00010001, B00010001, B00010101, B00010101, B00010001, B00010001, B00011110},
{B00001110, B00010001, B00010001, B00010001, B00011111, B00010001, B00010001, B00010001},
{B00011110, B00010001, B00010001, B00011110, B00010001, B00010001, B00010001, B00011110},
{B00000111, B00001000, B00010000, B00010000, B00010000, B00010000, B00001000, B00000111},
{B00011100, B00010010, B00010001, B00010001, B00010001, B00010001, B00010010, B00011100},
{B00011111, B00010000, B00010000, B00011110, B00010000, B00010000, B00010000, B00011111},
{B00011111, B00010000, B00010000, B00011110, B00010000, B00010000, B00010000, B00010000},
{B00001110, B00010001, B00010000, B00010000, B00010111, B00010001, B00010001, B00001110},
{B00010001, B00010001, B00010001, B00011111, B00010001, B00010001, B00010001, B00010001},
{B00011111, B00000100, B00000100, B00000100, B00000100, B00000100, B00000100, B00011111},
{B00011111, B00000100, B00000100, B00000100, B00000100, B00000100, B00010100, B00001000},
{B00010001, B00010010, B00010100, B00011000, B00010100, B00010010, B00010001, B00010001},
{B00010000, B00010000, B00010000, B00010000, B00010000, B00010000, B00010000, B00011111},
{B00010001, B00011011, B00011111, B00010101, B00010001, B00010001, B00010001, B00010001},
{B00010001, B00011001, B00011001, B00010101, B00010101, B00010011, B00010011, B00010001},
{B00001110, B00010001, B00010001, B00010001, B00010001, B00010001, B00010001, B00001110},
{B00011110, B00010001, B00010001, B00011110, B00010000, B00010000, B00010000, B00010000},
{B00001110, B00010001, B00010001, B00010001, B00010001, B00010101, B00010011, B00001111},
{B00011110, B00010001, B00010001, B00011110, B00010100, B00010010, B00010001, B00010001},
{B00001110, B00010001, B00010000, B00001000, B00000110, B00000001, B00010001, B00001110},
{B00011111, B00000100, B00000100, B00000100, B00000100, B00000100, B00000100, B00000100},
{B00010001, B00010001, B00010001, B00010001, B00010001, B00010001, B00010001, B00001110},
{B00010001, B00010001, B00010001, B00010001, B00010001, B00010001, B00001010, B00000100},
{B00010001, B00010001, B00010001, B00010001, B00010001, B00010101, B00010101, B00001010},
{B00010001, B00010001, B00001010, B00000100, B00000100, B00001010, B00010001, B00010001},
{B00010001, B00010001, B00001010, B00000100, B00000100, B00000100, B00000100, B00000100},
{B00011111, B00000001, B00000010, B00000100, B00001000, B00010000, B00010000, B00011111},
{B00001110, B00001000, B00001000, B00001000, B00001000, B00001000, B00001000, B00001110},
{B00010000, B00001000, B00001000, B00000100, B00000100, B00000010, B00000010, B00000001},
{B00001110, B00000010, B00000010, B00000010, B00000010, B00000010, B00000010, B00001110},
{B00000100, B00001010, B00010001, B00000000, B00000000, B00000000, B00000000, B00000000},
{B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00011111},
{B00001000, B00000100, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000},
{B00000000, B00000000, B00000000, B00001110, B00010010, B00010010, B00010010, B00001111},
{B00000000, B00010000, B00010000, B00010000, B00011100, B00010010, B00010010, B00011100},
{B00000000, B00000000, B00000000, B00001110, B00010000, B00010000, B00010000, B00001110},
{B00000000, B00000001, B00000001, B00000001, B00000111, B00001001, B00001001, B00000111},
{B00000000, B00000000, B00000000, B00011100, B00010010, B00011110, B00010000, B00001110},
{B00000000, B00000011, B00000100, B00000100, B00000110, B00000100, B00000100, B00000100},
{B00000000, B00001110, B00001010, B00001010, B00001110, B00000010, B00000010, B00001100},
{B00000000, B00010000, B00010000, B00010000, B00011100, B00010010, B00010010, B00010010},
{B00000000, B00000000, B00000100, B00000000, B00000100, B00000100, B00000100, B00000100},
{B00000000, B00000010, B00000000, B00000010, B00000010, B00000010, B00000010, B00001100},
{B00000000, B00010000, B00010000, B00010100, B00011000, B00011000, B00010100, B00010000},
{B00000000, B00010000, B00010000, B00010000, B00010000, B00010000, B00010000, B00001100},
{B00000000, B00000000, B00000000, B00001010, B00010101, B00010001, B00010001, B00010001},
{B00000000, B00000000, B00000000, B00010100, B00011010, B00010010, B00010010, B00010010},
{B00000000, B00000000, B00000000, B00001100, B00010010, B00010010, B00010010, B00001100},
{B00000000, B00011100, B00010010, B00010010, B00011100, B00010000, B00010000, B00010000},
{B00000000, B00001110, B00010010, B00010010, B00001110, B00000010, B00000010, B00000001},
{B00000000, B00000000, B00000000, B00001010, B00001100, B00001000, B00001000, B00001000},
{B00000000, B00000000, B00001110, B00010000, B00001000, B00000100, B00000010, B00011110},
{B00000000, B00010000, B00010000, B00011100, B00010000, B00010000, B00010000, B00001100},
{B00000000, B00000000, B00000000, B00010010, B00010010, B00010010, B00010010, B00001100},
{B00000000, B00000000, B00000000, B00010001, B00010001, B00010001, B00001010, B00000100},
{B00000000, B00000000, B00000000, B00010001, B00010001, B00010001, B00010101, B00001010},
{B00000000, B00000000, B00000000, B00010001, B00001010, B00000100, B00001010, B00010001},
{B00000000, B00000000, B00010001, B00001010, B00000100, B00001000, B00001000, B00010000},
{B00000000, B00000000, B00000000, B00011111, B00000010, B00000100, B00001000, B00011111},
{B00000010, B00000100, B00000100, B00000100, B00001000, B00000100, B00000100, B00000010},
{B00000100, B00000100, B00000100, B00000100, B00000100, B00000100, B00000100, B00000100},
{B00001000, B00000100, B00000100, B00000100, B00000010, B00000100, B00000100, B00001000},
{B00000000, B00000000, B00000000, B00001010, B00011110, B00010100, B00000000, B00000000}
};
void clearDisplay() {
 for (byte x=0; x<8; x++) {
 buffer[x] = B00000000;
 }
 screenUpdate();
}
void initMAX7219() {
 pinMode(DataPin, OUTPUT);
 pinMode(LoadPin, OUTPUT);
 pinMode(ClockPin, OUTPUT);
 clearDisplay();
 writeData(B00001011, B00000111); // scan limit set to 0:7
 writeData(B00001001, B00000000); // decode mode off
 writeData(B00001100, B00000001); // Set shutdown register to normal operation
 intensity(15); // Values 0 to 15 only (4 bit)
}
void intensity(int intensity) {
 writeData(B00001010, intensity); //B0001010 is the Intensity Register
}
void writeData(byte MSB, byte LSB) {
 byte mask;
 digitalWrite(LoadPin, LOW); // set loadpin ready to receive data
 // Send out MSB
 for (mask = B10000000; mask>0; mask >>= 1) { //iterate through bit mask
 digitalWrite(ClockPin, LOW);
 if (MSB & mask){ // if bitwise AND resolves to true
 digitalWrite(DataPin,HIGH); // send 1
 }
 else{ //if bitwise and resolves to false
 digitalWrite(DataPin,LOW); // send 0
 }
 digitalWrite(ClockPin, HIGH); // clock high, data gets input
 }
 // send out LSB for data
 for (mask = B10000000; mask>0; mask >>= 1) { //iterate through bit mask
 digitalWrite(ClockPin, LOW);
 if (LSB & mask){ // if bitwise AND resolves to true
 digitalWrite(DataPin,HIGH); // send 1
 }
 else{ //if bitwise and resolves to false
 digitalWrite(DataPin,LOW); // send 0
 }
 digitalWrite(ClockPin, HIGH); // clock high, data gets input
 }
 digitalWrite(LoadPin, HIGH); // latch the data
 digitalWrite(ClockPin, LOW);
}
void scroll(char myString[], int speed) {
 byte firstChrRow, secondChrRow;
 byte ledOutput;
 byte chrPointer = 0; // Initialise the string position pointer
 byte Char1, Char2; // the two characters that will be displayed
 byte scrollBit = 0;
 byte strLength = 0;
 unsigned long time;
 unsigned long counter;
 // Increment count till we reach the string
 while (myString[strLength]) {strLength++;}
 counter = millis();
 while (chrPointer < (strLength-1)) {
 time = millis();
 if (time > (counter + speed)) {
 Char1 = myString[chrPointer];
 Char2 = myString[chrPointer+1];
 for (byte y= 0; y<8; y++) {
 firstChrRow = pgm_read_byte(&font[Char1 - 32][y]);
 secondChrRow = (pgm_read_byte(&font[Char2 - 32][y])) << 1;
 ledOutput = (firstChrRow << scrollBit) | (secondChrRow >>
 (8 - scrollBit) );
 buffer[y] = ledOutput;
 }
 scrollBit++;
 if (scrollBit > 6) {
 scrollBit = 0;
 chrPointer++;
 }
 counter = millis();
 }
 }
}
void screenUpdate() {
 for (byte row = 0; row < 8; row++) {
 writeData(row+1, buffer[row]);
 }
}
void setup() {
 initMAX7219();
 Timer1.initialize(10000); // initialize timer1 and set interrupt period
 Timer1.attachInterrupt(screenUpdate);
}
void loop() {
 clearDisplay();
 scroll(" BEGINNING ARDUINO ", 45);
 scroll(" Chapter 7 - LED Displays ", 45);
 scroll(" HELLO WORLD!!! :) ", 45);
}

Arduino LED Dot Matrix Display Circuit

Arduino LED Dot Matrix Display Schematic

版权声明:本文为原创文章,版权归donstudio所有,欢迎分享本文,转载请保留出处!

本文链接:http://parentscn.com/?id=271

标签: Arduino

相关文章

Arduino Project 040 - Ultrasonic Distance Alarm

Arduino Project 040 - Ultrasonic Distance Alarm

The sensor consists of two primary components: a transmitter and a receiver . The transmitter is res...

Arduino Project 035 - Keypad 4X4 or 4X3

Arduino Project 035 - Keypad 4X4 or 4X3

Most of the time we are used key, button, or switch to get input value in our projects. When we inte...

Arduino Project 016 - L293D Motor Driver IC

Arduino Project 016 - L293D Motor Driver IC

In the previous project, you used a transistor to control the motor. In this project, you are going...

Arduino Project 029 - Control Stepper Motor ULN2004A

Arduino Project 029 - Control Stepper Motor ULN2004A

Stepper motors, due to their unique design, can be controlled to a high degree of accuracy without a...

C语言调试运行环境TurboC的安装

C语言调试运行环境TurboC的安装

上大学时学习《C语言程序设计》(第二版)作者谭浩强,大部分编程时间是在学校机房度过,每次点开桌面的TurboC图标,就开始在里面敲代码,然后保存程序Abc.C,下一步进行编译,如果编译成功的话,就可以...

 ​Arduino Project 051 - How to Connect Remote Control

​Arduino Project 051 - How to Connect Remote Control

Project 51 How to Connect Remote Control 4 Channel to Arduino// constants won't c...

发表评论

访客

看不清,换一张

◎欢迎参与讨论,请在这里发表您的看法和观点。