极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 22723|回复: 5

Arduino 8*8LED点阵模块验证成功

[复制链接]
发表于 2016-5-8 21:22:56 | 显示全部楼层 |阅读模式
1. 学习来源
https://www.arduino.cc/en/Tutorial/RowColumnScanning
2. 连线方法参看图片
3. 程序如下
/*
  Row-Column Scanning an 8x8 LED matrix with X-Y input

This example controls an 8x8 LED matrix using two analog inputs

created 27 May 2009
modified 30 Aug 2011
by Tom Igoe

This example works for the Lumex  LDM-24488NI Matrix. See
http://sigma.octopart.com/140413/datasheet/Lumex-LDM-24488NI.pdf
for the pin connections

For other LED cathode column matrixes, you should only need to change
the pin numbers in the row[] and column[] arrays

rows are the anodes
cols are the cathodes
---------

Pin numbers:
Matrix:
* Digital pins 2 through 13,
* analog pins 2 through 5 used as digital 16 through 19
Potentiometers:
* center pins are attached to analog pins 0 and 1, respectively
* side pins attached to +5V and ground, respectively.

This example code is in the public domain.

http://www.arduino.cc/en/Tutorial/RowColumnScanning

see also http://www.tigoe.net/pcomp/code/category/arduinowiring/514 for more
*/


// 2-dimensional array of row pin numbers:
const int row[8] = {
  2, 7, 19, 5, 13, 18, 12, 16
};

// 2-dimensional array of column pin numbers:
const int col[8] = {
  6, 11, 10, 3, 17, 4, 8, 9
};

// 2-dimensional array of pixels:
int pixels[8][8];

// cursor position:
int x = 5;
int y = 5;

void setup() {
  // initialize the I/O pins as outputs
  // iterate over the pins:
  for (int thisPin = 0; thisPin < 8; thisPin++) {
    // initialize the output pins:
    pinMode(col[thisPin], OUTPUT);
    pinMode(row[thisPin], OUTPUT);
    // take the col pins (i.e. the cathodes) high to ensure that
    // the LEDS are off:
    digitalWrite(col[thisPin], HIGH);
  }

  // initialize the pixel matrix:
  for (int x = 0; x < 8; x++) {
    for (int y = 0; y < 8; y++) {
      pixels[x][y] = HIGH;
    }
  }
}

void loop() {
  // read input:
  readSensors();

  // draw the screen:
  refreshScreen();
}

void readSensors() {
  // turn off the last position:
  pixels[x][y] = HIGH;
  // read the sensors for X and Y values:
  x = 7 - map(analogRead(A0), 0, 1023, 0, 7);
  y = map(analogRead(A1), 0, 1023, 0, 7);
  // set the new pixel position low so that the LED will turn on
  // in the next screen refresh:
  pixels[x][y] = LOW;

}

void refreshScreen() {
  // iterate over the rows (anodes):
  for (int thisRow = 0; thisRow < 8; thisRow++) {
    // take the row pin (anode) high:
    digitalWrite(row[thisRow], HIGH);
    // iterate over the cols (cathodes):
    for (int thisCol = 0; thisCol < 8; thisCol++) {
      // get the state of the current pixel;
      int thisPixel = pixels[thisRow][thisCol];
      // when the row is HIGH and the col is LOW,
      // the LED where they meet turns on:
      digitalWrite(col[thisCol], thisPixel);
      // turn the pixel off:
      if (thisPixel == LOW) {
        digitalWrite(col[thisCol], HIGH);
      }
    }
    // take the row pin low to turn off the whole row:
    digitalWrite(row[thisRow], LOW);
  }
}

4. 验证效果如图片,通过调整2个可调电阻,可以控制亮灯的LED位置。
5. 另外 8*8LED点阵模块不好接线,后来用两个面包板拼接,搞定了:)

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复

使用道具 举报

发表于 2016-5-9 11:56:14 | 显示全部楼层
赞一个,楼主可以试试直接用这个点阵编出一个贪吃蛇的出来没?
回复 支持 反对

使用道具 举报

发表于 2016-5-9 15:09:25 | 显示全部楼层
可以使用一个max7219芯片。这样使用起来非常方便。
回复 支持 反对

使用道具 举报

发表于 2016-5-9 16:49:16 | 显示全部楼层
回复 支持 反对

使用道具 举报

 楼主| 发表于 2016-5-10 16:57:09 | 显示全部楼层
爱瞌睡的盾 发表于 2016-5-9 11:56
赞一个,楼主可以试试直接用这个点阵编出一个贪吃蛇的出来没?

刚入手一个月,还没那个能力
回复 支持 反对

使用道具 举报

发表于 2019-6-2 16:35:48 | 显示全部楼层
这个值得学习
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-3-28 22:31 , Processed in 0.047404 second(s), 23 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表