【问题标题】:Arduino 8x8 led matrix lettersArduino 8x8 led 矩阵字母
【发布时间】:2019-03-10 18:23:13
【问题描述】:

我有一个 Arduino 8x8 led 连接到 Arduino 上的屏蔽上。现在我希望它显示一些文本。我发现了如何为每个字母制作正确的字节。但我不知道如何在我的显示器上点亮它。我在网上看到的教程不是很懂。我想使用一个功能,我可以在其中填写我想使用的字母以及它应该在显示屏上显示多长时间。像这样:displayLetter(byte letter[], int timeOnDisplay) 任何建议都很好。

我不知道型号,它包含在我的 Elektor Arduino 套件中。可以在链接中看到。目前我已经像这样声明了我所有的字节

byte A[] = {     
    B00000000,
    B00111100,
    B01100110,
    B01100110,
    B01111110,
    B01100110,
    B01100110,
    B01100110}; 

还有

void setup() { 
    Serial.begin(9600); 
    for (byte i = 2; i <= 13; i++) 
        pinMode(i, OUTPUT); 
    pinMode(A0, OUTPUT); 
    pinMode(A1, OUTPUT); 
    pinMode(A2, OUTPUT); 
    pinMode(A3, OUTPUT); 
}

我从在线教程中获得的。

我使用 Arduino Uno,我的 8x8 LED 通过屏蔽连接。

问候

【问题讨论】:

  • 您没有为您的模块提供任何链接或连接图到 Arduino 或 Arduino 板类型。

标签: arduino arduino-uno led


【解决方案1】:

在不知道矩阵的输入类型的情况下,我将假设它是通过列和行输入来控制的,而不是基于您提供的示例代码的 SPI。

下面是我快速拼凑的一个示例,用于演示循环遍历字母表并在指定时间内显示一个字母。此代码确实有效,您必须将 8x8 LED 矩阵输入连接到所提供代码中行和列的相应引脚标注(或更改代码引脚以匹配您的连接配置)。

这些通过多路复用工作,这意味着信号在 LED 之间共享,每行输入引脚连接到 8 个 LED,每列也连接到 8 个 LED。要打开特定的 LED,它需要来自它所连接的行引脚和它所连接的列引脚的正确信号。因此,例如,要打开右下角的 LED,需要向最后一行引脚和最后一列引脚发送信号;如果您想打开最后一列中的所有 LED,则需要向所有行引脚和最后一列引脚发送信号。

显示形状/字母需要更多的处理能力,因为您不能只打开几列和几行并让它们保持打开状态。为此,您需要循环遍历每一行和每一列,将所需的 LED 短时间打开,然后再次将其关闭;这样做的速度足够快,就好像所有的 LED 灯都同时亮了一样。

    /*
 Name:      Arduino8x8MatrixStackOverflow.ino
 Created:   3/10/2019 5:21:02 PM
 Author:    jjman
*/
//Connect these pins to the corresponding row input of the 8x8 matrix.
const unsigned char RowPins[] = {2,3,4,5,6,7,8,9};
//Connect these pins to the corresponding column input of the 8x8 matrix.
const unsigned char ColumnPins[] = {10,11,12,13,A0,A1,A2,A3};

unsigned char A[] = {B00000000,B00111100,B01100110,B01100110,B01111110,B01100110,B01100110,B01100110};
unsigned char B[] = {B01111000,B01001000,B01001000,B01110000,B01001000,B01000100,B01000100,B01111100};
unsigned char C[] = {B00000000,B00011110,B00100000,B01000000,B01000000,B01000000,B00100000,B00011110};
unsigned char D[] = {B00000000,B00111000,B00100100,B00100010,B00100010,B00100100,B00111000,B00000000};
unsigned char E[] = {B00000000,B00111100,B00100000,B00111000,B00100000,B00100000,B00111100,B00000000};
unsigned char F[] = {B00000000,B00111100,B00100000,B00111000,B00100000,B00100000,B00100000,B00000000};
unsigned char G[] = {B00000000,B00111110,B00100000,B00100000,B00101110,B00100010,B00111110,B00000000};
unsigned char H[] = {B00000000,B00100100,B00100100,B00111100,B00100100,B00100100,B00100100,B00000000};
unsigned char I[] = {B00000000,B00111000,B00010000,B00010000,B00010000,B00010000,B00111000,B00000000};
unsigned char J[] = {B00000000,B00011100,B00001000,B00001000,B00001000,B00101000,B00111000,B00000000};
unsigned char K[] = {B00000000,B00100100,B00101000,B00110000,B00101000,B00100100,B00100100,B00000000};
unsigned char L[] = {B00000000,B00100000,B00100000,B00100000,B00100000,B00100000,B00111100,B00000000};
unsigned char M[] = {B00000000,B00000000,B01000100,B10101010,B10010010,B10000010,B10000010,B00000000};
unsigned char N[] = {B00000000,B00100010,B00110010,B00101010,B00100110,B00100010,B00000000,B00000000};
unsigned char O[] = {B00000000,B00111100,B01000010,B01000010,B01000010,B01000010,B00111100,B00000000};
unsigned char P[] = {B00000000,B00111000,B00100100,B00100100,B00111000,B00100000,B00100000,B00000000};
unsigned char Q[] = {B00000000,B00111100,B01000010,B01000010,B01000010,B01000110,B00111110,B00000001};
unsigned char R[] = {B00000000,B00111000,B00100100,B00100100,B00111000,B00100100,B00100100,B00000000};
unsigned char S[] = {B00000000,B00111100,B00100000,B00111100,B00000100,B00000100,B00111100,B00000000};
unsigned char T[] = {B00000000,B01111100,B00010000,B00010000,B00010000,B00010000,B00010000,B00000000};
unsigned char U[] = {B00000000,B01000010,B01000010,B01000010,B01000010,B00100100,B00011000,B00000000};
unsigned char V[] = {B00000000,B00100010,B00100010,B00100010,B00010100,B00010100,B00001000,B00000000};
unsigned char W[] = {B00000000,B10000010,B10010010,B01010100,B01010100,B00101000,B00000000,B00000000};
unsigned char X[] = {B00000000,B01000010,B00100100,B00011000,B00011000,B00100100,B01000010,B00000000};
unsigned char Y[] = {B00000000,B01000100,B00101000,B00010000,B00010000,B00010000,B00010000,B00000000};
unsigned char Z[] = {B00000000,B00111100,B00000100,B00001000,B00010000,B00100000,B00111100,B00000000};

unsigned char *Alphabet[] = {A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z};
unsigned char AlphabetCharactersLower[] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};


unsigned char* DisplayBuffer = nullptr;

unsigned char DisplayIndex = 0;
unsigned long DisplayLetterBeginMilliseconds = 0;
unsigned long DisplayLetterEndMilliseconds = 0;
bool DisplayActive = false;

void setup()
{
    // Open serial port
    Serial.begin(9600);
    //Sets up all of the row pins to be used as outputs.
    for(unsigned char i = 0; i < sizeof(RowPins); i++)
    {
        pinMode(RowPins[i], OUTPUT);
    }
    //Sets up all of the column pins to be used as outputs.
    for(unsigned char i = 0; i < sizeof(ColumnPins); i++)
    {
        pinMode(ColumnPins[i], OUTPUT);
    }
}


//Resets the values used to time the duration of display.
void SetDisplayTiming(const unsigned displayMilliseconds)
{
    DisplayLetterBeginMilliseconds = millis();
    DisplayLetterEndMilliseconds = DisplayLetterBeginMilliseconds + displayMilliseconds;
    DisplayActive = true;
}

void UpdateDisplay()
{
    //Loop through rows.
    for(unsigned char i = 0; i < sizeof(RowPins); i++)
    {
        //Loop through columns.
        for(unsigned char j = 0; j < sizeof(ColumnPins); j++)
        {
            //Turn column on for the corresponding bit.
            digitalWrite(ColumnPins[j], ~DisplayBuffer[i] >> j & 1);
        }
        //Turn on row to activate led.
        digitalWrite(RowPins[i], 1);

        //Uncomment the delay to increase brightness.  With 8 rows, any delay greater than 2 ms will cause flickering.  This is due to the refresh rate dropping below 60hz.
        //delayMicroseconds(2000);

        //Turn row back off.
        digitalWrite(RowPins[i], 0);
    }
}


//Updates the DisplayBuffer to the corresponding letter.  Letter can be either uppercase, 'A', or lowercase 'a'.
void SetDisplayLetter(char letter)
{
    //If letter supplied is an uppercase letter, subtract 65 to zero the letter so it can be used as an index. (The 'A' character has an integer value of 65)
    if(letter > 64 && letter < 91) letter -= 65;
    //If letter supplied is a lowercase letter, subtract 97 to zero the letter so it can be used as an index.  (The 'a' character has an integer value of 97)
    else if(letter > 96 && letter < 123) letter -= 97;
    //Letter supplied is not a lowercase or uppercase letter, print error to serial.
    else
    {
        Serial.println("Error - Function: 'DisplayLetter' Cause: Specified Letter character is not an alphabet character");
        return;
    }
    DisplayBuffer = Alphabet[letter];
}
void SetDisplayLetter(const char letter, const unsigned displayMilliseconds)
{
    SetDisplayLetter(letter);
    SetDisplayTiming(displayMilliseconds);
}

//If it's time to display the next letter, do so.
void TryToDisplayNextLetter()
{
    //Letter is currently displayed, now we can check to see if enough time has elapsed for us to turn it off.
    if(DisplayActive)
    {
        //If enough time has elapsed, turn off display to allow display of the next letter.
        if(millis() > DisplayLetterEndMilliseconds)
        {
            DisplayActive = false;
        }
        return;
    }
    SetDisplayLetter(AlphabetCharactersLower[DisplayIndex],200);
    //Counts up the index for the next letter.
    DisplayIndex++;
    //Reset the index to zero if we just displayed the last letter in the alphabet.
    if(DisplayIndex == 26) DisplayIndex = 0;
}

//This example does not use delays and is non-blocking.
void loop()
{
    while(true)
    {
        TryToDisplayNextLetter();
        UpdateDisplay();
    }

    //Add other code as necessary.
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-01
    • 1970-01-01
    相关资源
    最近更新 更多