از این کد استفاده کن :
کد:
void setup()
{
Serial.begin(9600);
Serial.print("Setup: Examples of PrintHex usage\n\n");
}
void loop()
{
uint8_t ByteData[5]={0x01, 0x0F, 0x10, 0x11, 0xFF};
Serial.print("With uint8_t array: "); PrintHex8(ByteData,5); Serial.print("\n");
uint8_t ByteDatum=0x01;
Serial.print("With uint8_t scalar: "); PrintHex8(&ByteDatum,1); Serial.print("\n");
uint16_t Shorts[5]={0x0001, 0x00FF, 0x0100, 0xAAAA, 0xFFFF};
Serial.print("With uint16_t array: "); PrintHex16(Shorts,5); Serial.print("\n");
Serial.print("==========================================\n");
delay(10000);
}
void PrintHex8(uint8_t *data, uint8_t length) // prints 8-bit data in hex with leading zeroes
{
char tmp[16];
for (int i=0; i<length; i++) {
sprintf(tmp, "0x%.2X",data[i]);
Serial.print(tmp); Serial.print(" ");
}
}
void PrintHex16(uint16_t *data, uint8_t length) // prints 16-bit data in hex with leading zeroes
{
char tmp[16];
for (int i=0; i<length; i++)
{
sprintf(tmp, "0x%.4X",data[i]);
Serial.print(tmp); Serial.print(" ");
}
}