Can you indicate the different parts in your code above? What part are you referring to setting the slider and what part reads the voltage and current?
Notice this code is likely ineffective in setup
:
if (portSerial.available() >0) {
delay(100);
dutycycle=portSerial.readString();
}
When you read serial, you need to do ensure you verify the data you are processing. I dont know if you are getting any errors in the last part of your code. Check this:
void serialEvent (Serial portSerial)
{
String strMasukan = portSerial.readStringUntil ('\n');
if(strMasukan==null) return; //DO nothing
if(strMasukan.size() < 27) return; //DO nothing
//If the code makes it this far, it is is very likely you have good data
String strTegangan = strMasukan.substring (0, 7);
String strArus = strMasukan.substring (9, 14);
String strDaya = strMasukan.substring (16, 22);
String strFaktorDaya = strMasukan.substring (27);
labelTegangan.setText (strTegangan);
labelArus.setText (strArus);
labelDaya.setText (strDaya);
labelFaktorDaya.setText (strFaktorDaya);
}
A better example here
Kf