Arduino 高低 [英] Arduino HIGH LOW

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

问题描述

我有一个 Arduino,我想知道就实际值而言,HIGH 和 LOW 到底是什么意思……它们是带符号的整数吗?无符号整数?无符号字符???他们的价值观是什么?我猜测 HIGH 和 LOW 可能是所有位分别设置为 1 和 0 的无符号整数,但我不确定.我希望能够使用 HIGH 和 LOW 进行按位运算,或者将 HIGH 或 LOW 以外的值传递给 digitalWrite.另外,我如何将整数转换为 HIGH 或 LOW 以便我可以做到这一点?

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)都可以.不知道如果你传递给它一个不是 HIGH 和 LOW 的值,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.

由于 HIGH 和 LOW 只是简单定义的常量,因此您不能将整数转换为它们(该操作也没有意义).似乎您可以在任何需要 HIGH 和 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.

实际上这样做是一个坏主意,原因有很多 - HIGH 和 LOW 的定义可能会改变(不太可能但可能),并且从类型的角度来看它没有意义.相反,您应该在程序中使用逻辑来确定应该将 HIGH 还是 LOW 传递给函数调用,然后实际传递常量.

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天全站免登陆