Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matrix 5x7 LED矩阵的Arduino代码不工作_Matrix_Arduino_Led - Fatal编程技术网

Matrix 5x7 LED矩阵的Arduino代码不工作

Matrix 5x7 LED矩阵的Arduino代码不工作,matrix,arduino,led,Matrix,Arduino,Led,我想知道我在这个项目中做错了什么。我有一个8x8矩阵代码,并试图使其适应我的5x7矩阵 所以,重要的是要记住,我使用的是FrequencyTimer2库,由于端口数量的原因,我只能使用橙色LED LED矩阵5x7映射: 第一个示例代码 改编代码: /* * Show messages on an 8x8 LED matrix, * scrolling from right to left. * * Uses FrequencyTimer2 library to * constantly

我想知道我在这个项目中做错了什么。我有一个8x8矩阵代码,并试图使其适应我的5x7矩阵

所以,重要的是要记住,我使用的是FrequencyTimer2库,由于端口数量的原因,我只能使用橙色LED

LED矩阵5x7映射:

第一个示例代码

改编代码:

/*
 * Show messages on an 8x8 LED matrix,
 * scrolling from right to left.
 *
 * Uses FrequencyTimer2 library to
 * constantly run an interrupt routine
 * at a specified frequency. This
 * refreshes the display without the
 * main loop having to do anything.
 *
 */

#include <FrequencyTimer2.h>

#define SPACE { \
    {0, 0, 0, 0, 0},  \
    {0, 0, 0, 0, 0}, \
    {0, 0, 0, 0, 0}, \
    {0, 0, 0, 0, 0}, \
    {0, 0, 0, 0, 0}, \
    {0, 0, 0, 0, 0}, \
    {0, 0, 0, 0, 0}, \
}

#define H { \
    {1, 0, 0, 1, 0}, \
    {1, 0, 0, 1, 0}, \
    {1, 0, 0, 1, 0}, \
    {1, 1, 1, 1, 0}, \
    {1, 0, 0, 1, 0}, \
    {1, 0, 0, 1, 0}, \
    {1, 0, 0, 1, 0}, \
 }

#define E  { \
    {1, 1, 1, 1, 0}, \
    {1, 0, 0, 0, 0}, \
    {1, 0, 0, 0, 0}, \
    {1, 1, 1, 1, 0}, \
    {1, 0, 0, 0, 0}, \
    {1, 0, 0, 0, 0}, \
    {1, 1, 1, 1, 0}  \
}

#define L { \
    {1, 0, 0, 0, 0}, \
    {1, 0, 0, 0, 0}, \
    {1, 0, 0, 0, 0}, \
    {1, 0, 0, 0, 0}, \
    {1, 0, 0, 0, 0}, \
    {1, 0, 0, 0, 0}, \
    {1, 1, 1, 1, 0}  \
}

#define O { \
    {1, 1, 1, 1, 0}, \
    {1, 0, 0, 1, 0}, \
    {1, 0, 0, 1, 0}, \
    {1, 0, 0, 1, 0}, \
    {1, 0, 0, 1, 0}, \
    {1, 0, 0, 1, 0}, \
    {1, 1, 1, 1, 0}  \
}

byte col = 0;
byte leds[5][7];

// pin[xx] on LED matrix connected to nn on Arduino (-1 is dummy to make array start at pos 1)
int pins[14]= {-1, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};

// col[xx] of LEDs = pin yy on LED matrix
int cols[5] = {pins[13], pins[11], pins[10], pins[4], pins[6]};

// row[xx] of LEDs = pin yy on LED matrix
int rows[7] = {pins[5], pins[2], pins[3], pins[9], pins[8], pins[7], pins[12]};
const int numPatterns = 6;
byte patterns[numPatterns][8][8] = {
  H,E,L,L,O,SPACE
};

int pattern = 0;

void setup() {
  // Sets the pins as output
  for (int i = 1; i <= 16; i++) {
    pinMode(pins[i], OUTPUT);
  }

  // Set up cols and rows
  for (int i = 1; i <= 8; i++) {
    digitalWrite(cols[i - 1], LOW);
  }

  for (int i = 1; i <= 8; i++) {
    digitalWrite(rows[i - 1], LOW);
  }

  clearLeds();

  // Turn off toggling of pin 11
  FrequencyTimer2::disable();
  // Set refresh rate (interrupt timeout period)
  FrequencyTimer2::setPeriod(2000);
  // Set interrupt routine to be called
  FrequencyTimer2::setOnOverflow(display);

  setPattern(pattern);
}

void loop() {
    pattern = ++pattern % numPatterns;
    slidePattern(pattern, 60);
}

void clearLeds() {
  // Clear display array
  for (int i = 0; i < 8; i++) {
    for (int j = 0; j < 8; j++) {
      leds[i][j] = 0;
    }
  }
}

void setPattern(int pattern) {
  for (int i = 0; i < 8; i++) {
    for (int j = 0; j < 8; j++) {
      leds[i][j] = patterns[pattern][i][j];
    }
  }
}

void slidePattern(int pattern, int del) {
  for (int l = 0; l < 8; l++) {
    for (int i = 0; i < 7; i++) {
      for (int j = 0; j < 8; j++) {
        leds[j][i] = leds[j][i+1];
      }
    }
    for (int j = 0; j < 8; j++) {
      leds[j][7] = patterns[pattern][j][0 + l];
    }
    delay(del);
  }
}

// Interrupt routine
void display() {
  digitalWrite(cols[col], LOW);  // Turn whole previous column off
  col++;
  if (col == 8) {
    col = 0;
  }
  for (int row = 0; row < 8; row++) {
    if (leds[col][7 - row] == 1) {
      digitalWrite(rows[row], LOW);  // Turn on this LED
    }
    else {
      digitalWrite(rows[row], HIGH); // Turn off this LED
    }
  }
  digitalWrite(cols[col], HIGH); // Turn whole column on at once (for equal lighting times)
}

项目概述:您的问题到底是什么?如果您还没有一次点亮一个LED,建议您进行行/列扫描,以确保所有接线和pin码正确。换句话说,请确保硬件使用的是尽可能简单的代码。我不确定您的代码出了什么问题,但我可能会为您提供一个更简单的解决方案。它只需要一个串行端口,即2个IO引脚。您不关心多路复用或其他复杂的控件。专注于你的项目。请看这里: