Serial.write(0x0d); // hex
Serial.write(13); // ASCII
Serial.write('\r'); // char
Is one more efficient? I read how it depends on the terminal program. So does that mean the IDE? (This is my first time working with serial comm.)
Arduino Stack Exchange is a question and answer site for developers of open-source hardware and software that is compatible with Arduino. It only takes a minute to sign up.Sign up to join this community
As mentioned before they are all the same. The thing you have to rememeber is that the compiler takes the human readable code you write and turns it into the instructions the processor can understand. If you want to explore ways the compiler does thing you can compile the program into the hex file and then compare. Or for even less detail, but much easier, look at the size of the file created when you compile in the IDE using just the one line in question inside the setup function
write(0x0d) ----> 1334 bytes write(13) ----> 1334 bytes write('\r') ----> 1334 bytes
For this simple example we can assume that all three of these are producing the exact same hex file. There are many more complicated example of different ways to do the same task that may produce more or less efficient code, but in this case the compiler is going to produce the same instruction set to the processor.
As pointed out in the comments, I am not saying that because they are the same size they must be the same hex code. As any single byte being written would produce the same size code, but not the same result. But when comparing two methods that we know are the same functionality ( 0x0d and '\r') and they produce the same size binary, then we can assume the compiler reduced them to the same code.