Arduino HIGH LOW

后端 未结 4 1101
被撕碎了的回忆
被撕碎了的回忆 2021-02-06 23:38

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

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-07 00:25

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

    void digitalWrite(uint8_t, uint8_t);
    

    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.

提交回复
热议问题