How to convert a String var to unsigned char var[16]; the variables I will use to decrypt the value.
The code is :
void komunikasiSerial(void) {
if (Serial2.available() > 0) {
String baca = Serial2.readString();
char dataChar[16];
baca.toCharArray(dataChar, sizeof(baca));
unsigned char tes = (unsigned char)dataChar
Serial.println(tes);
}
}
-- Error --
if (Serial2.available() > 0) {
^~
exit status 1
cast from 'char*' to 'unsigned char' loses precision [-fpermissive]
You're missing a semi-colon at unsigned char tes = (unsigned char)dataChar. After that your function compiles (with warnings). If it does not compile, post your complete sketch; please use code tags when posting code (and error messages) as described in How to get the best out of this forum.
dataChar is an array, test is a character, hence the cast warning. This will work
unsigned char *tes = (unsigned char*)dataChar;
But you can't print tes that way; use a for-loop to print all elements.