Arduino的高低 [英] Arduino HIGH LOW

查看:497
本文介绍了Arduino的高低的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Arduino和我想知道到底是什么高,低意味着尽可能实际值去...难道他们签署整数?无符号整型?无符号的字符?他们有什么价值?我猜测,HIGH和LOW可能是无符号整数所有设置分别为1和0的位,但我不知道。我希望能够用HIGH做到位运算和LOW或通过比高其他或低值digitalWrite。此外,我将如何转换为高或低一个整数,所以我能做到这一点?

I have an Arduino and I am wondering exactly what HIGH and LOW mean as far as actual values go... Are they signed ints? Unsigned ints? Unsigned chars??? What are their values? I am guessing that HIGH and LOW are probably unsigned ints with all of the bits set to 1 and 0 respectively, but I'm not sure. I would like to be able to do bitwise operations using HIGH and LOW or pass values other than HIGH or LOW to digitalWrite. Also, how would I cast an integer to HIGH or LOW so I could do this?

推荐答案

如果你想其他的值传递给digitalWrite(),你可以看一下函数原型

If you want to pass other values to digitalWrite() you can have a look at the function prototype

void digitalWrite(uint8_t, uint8_t);

因此​​,任何整数值(当然,从0到255)会工作。不知道是什么digitalWrite的行为()可以,如果你通过它不是高和低以外的值。

So any integer value (well, 0 through 255) would work. No idea what the behavior of digitalWrite() could be if you passed it a value other than HIGH and LOW.

由于顶端和底端简单地定义常量,你可以不投一个整数他们(也即会操作有意义)。看样子,你可以在任何地方使用了高,低,预计一个整数。

Since HIGH and LOW are simply defined constants, you can't cast an integer to them (nor would that operation make sense). It appears that you could use an integer anywhere that HIGH and LOW was expected.

其实这样做是一个坏主意,虽然,有许多原因 - 高,低的定义可能会改变(不可能的,但有可能),它不从类型的角度来看是有意义的。相反,你应该使用逻辑程序,以确定高或低是否应该传递给函数调用,然后实际上传递保持不变。

Actually doing this is a bad idea though, for lots of reasons - the definitions of HIGH and LOW could change (unlikely but possible) and it doesn't make sense from a type perspective. Instead, you should use logic in your program to determine whether HIGH or LOW should be passed to the function call, and then actually pass the constant.

这篇关于Arduino的高低的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆