Arduino示例代码讲授:Row-Column Scanning an 8x8 LED matrix with X-Y input LED矩阵

[复制链接]
发表于 2025-9-30 02:41:49 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

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

×
Row-Column Scanning an 8x8 LED matrix with X-Y input LED矩阵

这段代码是一个Arduino示例步伐,用于通过行-列扫描控制一个8x8的LED矩阵。它利用两个模拟输入(比方电位器)来控制光标的位置,并在LED矩阵上表现光标的位置。
  1. /*
  2.   Row-Column Scanning an 8x8 LED matrix with X-Y input
  3. This example controls an 8x8 LED matrix using two analog inputs
  4. created 27 May 2009
  5. modified 30 Aug 2011
  6. by Tom Igoe
  7. This example works for the Lumex  LDM-24488NI Matrix. See
  8. http://sigma.octopart.com/140413/datasheet/Lumex-LDM-24488NI.pdf
  9. for the pin connections
  10. For other LED cathode column matrixes, you should only need to change
  11. the pin numbers in the row[] and column[] arrays
  12. rows are the anodes
  13. cols are the cathodes
  14. ---------
  15. Pin numbers:
  16. Matrix:
  17. * Digital pins 2 through 13,
  18. * analog pins 2 through 5 used as digital 16 through 19
  19. Potentiometers:
  20. * center pins are attached to analog pins 0 and 1, respectively
  21. * side pins attached to +5V and ground, respectively.
  22. This example code is in the public domain.
  23. http://www.arduino.cc/en/Tutorial/RowColumnScanning
  24. see also http://www.tigoe.net/pcomp/code/category/arduinowiring/514 for more
  25. */
  26. // 2-dimensional array of row pin numbers:
  27. const int row[8] = {
  28.    
  29.    
  30.   2, 7, 19, 5, 13, 18, 12, 16
  31. };
  32. // 2-dimensional array of column pin numbers:
  33. const int col[8] = {
  34.    
  35.    
  36.   6, 11, 10, 3, 17, 4, 8, 9
  37. };
  38. // 2-dimensional array of pixels:
  39. int pixels[8][8];
  40. // cursor position:
  41. int x = 5;
  42. int y = 5;
  43. void setup() {
  44.    
  45.    
  46.   // initialize the I/O pins as outputs
  47.   // iterate over the pins:
  48.   for (int thisPin = 0; thisPin < 8; thisPin++) {
  49.    
  50.    
  51.     // initialize the output pins:
  52.     pinMode(col[thisPin], OUTPUT);
  53.     pinMode(row[thisPin], OUTPUT);
  54.     // take the col pins (i.e. the cathodes) high to ensure that
  55.     // the LEDS are off:
  56.     digitalWrite(col[thisPin], HIGH);
  57.   }
  58.   // i
复制代码
回复

使用道具 举报

登录后关闭弹窗

登录参与点评抽奖  加入IT实名职场社区
去登录
快速回复 返回顶部 返回列表