Serial.write

Can someone help convert this from B4A?

Dim hex As String = "025648504853034850" 'Y2 0FF
For i=0 To hex.Length -1 Step 2
    AStream.Write(Array As Byte( hex.SubString2( i, i+2)))
Next

The String class has similar functions. I believe if you look here you won't need help with this conversion:

This works but i would like to use
one string variable

void Y0_ON() {
 Serial.write(02);
 Serial.write(55);
 Serial.write(48);
 Serial.write(48);
 Serial.write(48);
 Serial.write(53);
 Serial.write(03);
 Serial.write(70);
 Serial.write(70);
}

I think that this will do the same. It takes two characters, converts them and sends it over the serial port.

char txt[] = "025648504853034850";

void setup()
{
  char tmp[3];
  memset(tmp, '\0', sizeof(tmp));
  for (uint8_t cnt = 0; cnt < strlen(txt); cnt += 2)
  {
    tmp[0] = txt[cnt * 2];
    tmp[1] = txt[cnt * 2 + 1];

    Serial.write((byte)atoi(tmp));
  }
}

void loop()
{
}

Not tested.

Thanks!!!
I will work with that.

byte Y2Off[] = {0x02, 0x56, 0x48, 0x50, 0x48, 0x53, 0x03, 0x48, 0x50};
    Serial.write(Y2Off, sizeof Y2Off);

@johnwasser

I suspect that the data cones in as text from somewhere. Else the question is why a String was used in the B4A code.

sterretje:
@johnwasser
I suspect that the data cones in as text from somewhere. Else the question is why a String was used in the B4A code.

That could be. I know nothing about "B4A". If the string constant wasn't part of the code to be translated I would have expected something like:

Jay_Arduino:
Can someone help convert this from B4A? The variable 'hex' is a string that contains hexadecimal digits, like "025648504853034850".

'Y2 0FF

For i=0 To hex.Length -1 Step 2
   AStream.Write(Array As Byte( hex.SubString2( i, i+2)))
Next