I’m still working with MIT app inventor and i am trying to change the pwm using a slider but i do not kwon how to read tha value in my ESP32 i don’t kwon what function use or how to read it without become my ESP32 into a client because i want to send and receives data
You should implemente a similar method as the ON/OFF buttons. Basically, when you move the slider you need to send those PWM/slider values to the ESP32 (like you would do with the buttons):
but how can i get the value from the slider in my code?, the problem is that the value is integer
// Setup callback when new value is received (from the Android application)
class MyCallbacks: public BLECharacteristicCallbacks {
void onWrite(BLECharacteristic *pCharacteristic) {
std::string rxValue = pCharacteristic->getValue();
if(rxValue.length() > 0) {
Serial.print(“Received value: “);
for(int i = 0; i < rxValue.length(); i++) {
Serial.print(rxValue[i]);
}
ledcWrite(ledChannel,atoi(rxValue) );
}
}
};
do not kwon what to do
Error rxValue must be unit_32, so i have the problem in the mit app i can’t save the slider value as string or i do not kwon how do that, (that will solve my porblem) or how can i get in my arduino’s code a function that recives integer number o unit_32
But which code line is giving you that error? Unfortunately I’m not understanding your exact problem. This is a variable conversion error. What’s the rxValue variable type and which type do you need?
class MyCallbacks: public BLECharacteristicCallbacks {
void onWrite(BLECharacteristic *pCharacteristic) {
std::string rxValue = pCharacteristic->getValue();
if(rxValue.length() > 0) {
Serial.print(“Received value: “);
for(int i = 0; i < rxValue.length(); i++) {
Serial.print(rxValue[i]);
}
here is the problem pwm use led channel and an integer for duty cycle but rxvalue is a String and MIT APP inventor doesn't send the slider value as a string so i must send it as a byte or as integer and that is the problem i'll never will eable to get that value because rxvalue just receives Strings
You can convert a String to an integer using the .toInt() method. You can find more information about that function here: https://www.arduino.cc/reference/en/language/variables/data-types/string/functions/toint/