Sending Hex with Serial

Hi there,

I have a Mega which i will use to send data to a device requiring HEX values.

The problem is, that i need to be able to send HEX values based on buttons with each button having a different value to send.

For example,

  • button A needs to send 0x02 when clicked
  • button B needs to send 0x03 when clicked

How can i send these HEX values similar to this using a variable instead inside the write command:

Serial.write(0x02)

Thanks for any help

How can i send these HEX values similar to this using a variable

byte clueless = 0x02;
Serial.write(clueless);