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

Arduino Project 021 - LED Dot Matrix Display - Scrolling Message

RonWang8个月前 (10-08)电子编程305

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://www.donstudio.cn/?id=271

标签: Arduino

相关文章

Arduino Project 002 - LED SOS Morse Code Singal

Arduino Project 002 - LED SOS Morse Code Singal

Arduino 电子编程--灯项目及控制,主要使用Arduino编程控制LED灯,实现基本控制Project 2 LED闪烁S.O.S信号。项目2 Project 2 S.O.S...

Arduino Project 011 - Piezo Sounder Alarm

Arduino Project 011 - Piezo Sounder Alarm

Arduino project - sounder and sensors : Include project 11 Piezo Sounder Alarm ,Project piezo sounde...

 Arduino Project 033 - 4 Digital 7 Segment Display

Arduino Project 033 - 4 Digital 7 Segment Display

Showing Heep and number 0-9 on a Common Anode 7-segment LED display. Displays the numbers 0-9 on the...

Arduino Project 026 - Dual Servo Control

Arduino Project 026 - Dual Servo Control

This project you’ll create another simple project, but this time you’ll control two servos using com...

Arduino Project 027 - Joystick Servo Control

Arduino Project 027 - Joystick Servo Control

In this tutorial, we are going to learn how to use Arduino and a joystick to control two servo motor...

 ​Arduino Project 049 - IR Remote Control

​Arduino Project 049 - IR Remote Control

Project 49 IR Remote Control/* Project 49 IR Remote Control  * C...