Arduino 数据类型


当前第2页 返回上一页

例子

int counter = 32 ;// declaration of variable with type int and initialize it with 32

Unsigned int

unsigned int(无符号整数)与int相同,存储2字节。然而,它们只存储正值,产生0到65535(2^16)-1的有效范围。Due存储4字节(32位)值,范围从0到4294967295(2^32-1)。

例子

Unsigned int counter = 60 ; // declaration of variable with 
   type unsigned int and initialize it with 60

Word

在Uno和其他基于ATMEGA的板上,一个word存储一个16位无符号数。在Due和Zero上,它存储一个32位无符号数。

例子

word w = 1000 ;//declaration of variable with type word and initialize it with 1000

Long

Long变量是用于数字存储的扩展大小变量,存储32位(4字节),从-2147483648到2147483647。

例子

Long velocity = 102346 ;//declaration of variable with type Long and initialize it with 102346

unsigned long

unsigned long变量是用于数字存储的扩展大小变量,并存储32位(4字节)。与标准的long不同,unsigned long不会存储负数,它们的范围为0到4294967295(2^32-1)。

例子

Unsigned Long velocity = 101006 ;// declaration of variable with 
   type Unsigned Long and initialize it with 101006

short

short是16位数据类型。在所有Arduinos(基于ATMega和ARM)上,一个short存储一个16位(2字节)值。这产生-32768至32767的范围(最小值为-2^15,最大值为(2^15)-1)。

例子

short val = 13 ;//declaration of variable with type short and initialize it with 13

float

浮点数的数据类型是具有小数点的数字。浮点数通常用于近似模拟值和连续值,因为它们的分辨率高于整数。

浮点数可以大到3.4028235E+38,也可以低到-3.4028235E+38。它们被存储为32位(4字节)信息。

例子

float num = 1.352;//declaration of variable with type float and initialize it with 1.352

double

在Uno和其他基于ATMEGA的板上,双精度浮点数占用四个字节。也就是说,double实现与float完全相同,精度没有增益。在Arduino Due上,double具有8字节(64位)精度。

例子

double num = 45.352 ;// declaration of variable with type double and initialize it with 45.352



标签:Arduino

返回前面的内容

相关阅读 >>

Arduino 闪烁led

Arduino 音调库

Arduino 字符串对象

Arduino 渐变led

Arduino 函数

Arduino 伺服电机

Arduino 通信

Arduino 数组

Arduino 步进电机

Arduino 连接开关

更多相关阅读请进入《Arduino》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...