T-vK / ESP32-BLE-Mouse

Bluetooth LE Mouse library for the ESP32 (Arduino IDE compatible)
724 stars 139 forks source link

How can I convert the number received by the serial port into char? #36

Open bbhxwl opened 2 years ago

bbhxwl commented 2 years ago

image

alexz006 commented 1 year ago
if(Serial.available()){
    String inputCOM = Serial.readStringUntil('\n'); // m-move:20,30,-1
    if(inputCOM.indexOf("m-move:") != -1){
        inputCOM.replace("m-move:", "");
        inputCOM.replace(" ", "");

        String xVal = inputCOM.substring(0,inputCOM.indexOf(","));

        inputCOM.remove(0, xVal.length()+1);
        String yVal = inputCOM.substring(0,inputCOM.indexOf(","));

        inputCOM.remove(0, yVal.length()+1);
        String wheel = inputCOM.substring(0);

        //Serial.println(xVal + "," + yVal + "," + wheel);
        bleMouse.move(atoi(xVal.c_str()), atoi(yVal.c_str()), atoi(wheel.c_str()));
    }
}