Ok, so I am writing this code where I need to send this message:
Serial.write(0x7E);
Serial.write(0xFF);
Serial.write(0x06);
Serial.write(0x03);
Serial.write(0x00);
Serial.write(0x00);
Serial.write(0x01);
Serial.write(0xEF);
But isn't there an easier way of doing this? Like shouldn't I be able to do this in ascii? or no?
system
June 24, 2016, 7:45pm
2
Did you forget ", HEX" ?
(ASCII is a seven bit code, so "0xFF" isn't ASCII)
static const uint8_t MessageInABottle[] = { 0x7E, 0xFF, 0x06, 0x03, 0x00, 0x00, 0x01, 0xEF };
Serial.write( MessageInABottle, sizeof(MessageInABottle) );
Maybe less typing. Probably uses less Flash.
The benefit to your method is that it uses no SRAM.
SlinkyMation:
Like shouldn't I be able to do this in ascii? or no?
Do any of those values correspond to ASCII characters?
static const uint8_t MessageInABottle[] = { 0x7E, 0xFF, 0x06, 0x03, 0x00, 0x00, 0x01, 0xEF };
Serial.write( MessageInABottle, sizeof(MessageInABottle) );
Would doing something like this be practical?
static const uint8_t MessageInABottle[] = { 0x7E, 0xFF, 0x06, 0x03, 0x00, 0x00, 0x01, 0xEF };
#define Throw_Bottle Serial.write( MessageInABottle, sizeof(MessageInABottle) );
Throw_Bottle
system
June 24, 2016, 7:59pm
5
Practical?
Yes.
Sensible?
No.
TL;DR: See post above.
SlinkyMation:
Would doing something like this be practical?
Only if you have a specific reason to use a macro instead of a function. I can address your situation without a response: No, that is not practical. Use a function...
static void Throw_Bottle( void )
{
static const uint8_t MessageInABottle[] = { 0x7E, 0xFF, 0x06, 0x03, 0x00, 0x00, 0x01, 0xEF };
Serial.write( MessageInABottle, sizeof(MessageInABottle) );
}
If you want the serial to send ASCII, use Serial.print / Serial.println instead of Serial.write ...