1

このプロジェクトで何が間違っているのか知りたいです。私は 8x8 マトリックス コードを持っていて、それを 5x7 LEDマトリックスに適合させようとしました。

したがって、FrequencyTimer2 ライブラリを使用していること、およびArduino Uno のポートの量のためにオレンジ色の 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)
}
4

0 に答える 0