马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
Row-Column Scanning an 8x8 LED matrix with X-Y input LED矩阵
这段代码是一个Arduino示例步伐,用于通过行-列扫描控制一个8x8的LED矩阵。它利用两个模拟输入(比方电位器)来控制光标的位置,并在LED矩阵上表现光标的位置。
- /*
- 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);
- }
- // i
复制代码 |