极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 12621|回复: 7

arduino基础问题_端口如何统一命名

[复制链接]
发表于 2013-3-18 11:24:47 | 显示全部楼层 |阅读模式
想实现如下功能:
int mypin[]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,a0,a1,a2,a3,a4,a5}
前面14个是数字口,后面6个为拟模口。
但每明显a0的数据类型不是int的,所以报错。
请教我应该如何把所有的模拟口也放到变量里,另起一个数组也行。不要告诉我把int改为string,那样也不行,digitalRead不接受string类型。
回复

使用道具 举报

发表于 2013-3-18 11:28:22 | 显示全部楼层
本帖最后由 histamine 于 2013-3-18 11:29 编辑

pins_arduino.h

  1. static const uint8_t A0 = 14;
  2. static const uint8_t A1 = 15;
  3. static const uint8_t A2 = 16;
  4. static const uint8_t A3 = 17;
  5. static const uint8_t A4 = 18;
  6. static const uint8_t A5 = 19;
  7. static const uint8_t A6 = 20;
  8. static const uint8_t A7 = 21;
复制代码


写成
uint8_t mypin[]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,A0,A1,A2,A3,A4,A5};
就行了
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-3-18 11:33:17 | 显示全部楼层
想问一下,如何直接digitalRead【14】脚就是读取a0的值吗?
回复 支持 反对

使用道具 举报

发表于 2013-3-18 11:33:50 | 显示全部楼层
A0,A1,A2,A3,依次是14,15,16,17号端口,以此类推。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-3-18 11:37:12 | 显示全部楼层
那我没必要把14转来 a0,直接如下就可以了
int mypin[]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19}
回家就测试一下,成功了来结贴。

回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-3-18 11:38:03 | 显示全部楼层
本帖最后由 openmmoo 于 2013-3-18 11:40 编辑

那我没必要把14转来 a0,直接如下就可以了
int mypin[]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19}
回家就测试一下,成功了来结贴。

又解决一个问题。学点东西真不容易呀!
好在有极客工仿。
回复 支持 反对

使用道具 举报

发表于 2015-4-8 15:56:58 | 显示全部楼层
为什么我看Arduino.h中,函数传递进去的都是uint_8呢?
回复 支持 反对

使用道具 举报

发表于 2015-4-10 14:13:28 | 显示全部楼层
znstj 发表于 2015-4-8 15:56
为什么我看Arduino.h中,函数传递进去的都是uint_8呢?

stdint.h中的.
typedef signed char int8_t;
typedef unsigned char uint8_t;
typedef signed int int16_t;
typedef unsigned int uint16_t;
typedef signed long int int32_t;
typedef unsigned long int uint32_t;

定一些常用的int类型而已.
回复 支持 反对

使用道具 举报

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

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

Archiver|联系我们|极客工坊

GMT+8, 2024-5-18 10:25 , Processed in 0.039739 second(s), 21 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

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