如何高效读取Arduino Mega上20个随机排列的引脚?
#define x1 3
#define x2 14
#define x3 22
#define x4 52
#define x5 24
#define x6 50
#define x7 26
#define x8 48
#define x9 28
#define x10 46
#define x11 2
#define x12 15
#define x13 23
#define x14 53
#define x15 25
#define x16 51
#define x17 27
#define x18 49
#define x19 29
#define x20 47
正如您所看到的,引脚号不遵循特定的顺序?我不想使用 20 个 if 语句来读取每个引脚。我正在考虑使用数组,但是如何有效地实现呢?
We have pins defined on Arduino Mega this way:
#define x1 3
#define x2 14
#define x3 22
#define x4 52
#define x5 24
#define x6 50
#define x7 26
#define x8 48
#define x9 28
#define x10 46
#define x11 2
#define x12 15
#define x13 23
#define x14 53
#define x15 25
#define x16 51
#define x17 27
#define x18 49
#define x19 29
#define x20 47
As you can see the pin numbers do not follow a specific order? I do not want to use 20 if
statements to read each pin. I am thinking of using arrays, but how do I do it efficiently?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
那么您的应用程序中有 x1-20,并且您已将这些值连接到 I/O 连接器上的任意引脚?
PS简单地定义它们之间的数组映射
。您不再需要 #defines,只需使用
x[N]
代替xN
即可。So you have x1-20 in your application, and you have these values hooked up to arbitrary pins on the I/O connector?
Simply define an array mapping between them
PS. You no longer need the #defines anymore, just use
x[N]
in place ofxN
.