How to `Serial.print()` “full” hexadecimal bytes?

前端 未结 6 2020
猫巷女王i
猫巷女王i 2021-01-18 02:17

I am programming Arduino and I am trying to Serial.print() bytes in hexadecimal format \"the my way\" (keep reading for more information).

That is, by u

6条回答
  •  感动是毒
    2021-01-18 03:10

    sorry - not enough reputation to comment but found previous answer is not fully correct. Actually, the nice light way to code it should be :

    void p(byte X) { if (X < 10) {Serial.print("0");} ...

    giving the code:

    void p(byte X) {
    
       if (X < 10) {Serial.print("0");}
    
       Serial.println(X, HEX);
    
    }
    

    And in the main code:

    p(byte1);  // etc.
    

    hope this helps

提交回复
热议问题