adding button press over bluetooth while sending throttle info!

I made a remote controller to control a motorized platform. I send the throttle voltage through pin A0 on a NANO then tx over bluetooth. It works great , but now I also want to send button press info as well.

int tval =0;
tval = analogRead(A0);
tval= map(tval, 0, 1023, 0, 255);
hc05.write(tval);
delay(10);

I was thinking of

hc05.println(“P”);
hc05.write(tval);

if digital.read(button1) == HIGH{
hc05.println(“B1”);
}
else
hc05.println(“B0”);
}

Then on the rx end , I’d strip off the first character and go to either the B code or P code!

What is the best way! Any other suggestions?

Thanks
Pete

You may want to capture the button press as singular and instantaneous, unless you want it to broadcast for the duration of the press.

No , as long as the press is detected and sent that will work. No need to check if continually pressed or a long press!

peterg2000:
No , as long as the press is detected and sent that will work. No need to check if continually pressed or a long press!

if digital.read(button1) == HIGH{
hc05.println("B1");
}
else
hc05.println("B0");
}

will print “B1” or “B0” every 10 milliseconds they way you have your code now.