Error: "conversion from 'String' to 'bool' is ambiguous"

I am trying to make a piece of code to control my remote controlled car over the internet, the inputs for setleft and setright can be anywhere in between 0 and 512, here is the code:

int leftmotor1 = D2;
int leftmotor2 = D3;
int rightmotor1 = D4;
int rightmotor2 = D5;
int enable = D6;
int do1;
int do2;
int do3;
int do4;
int allow;
int valint1;
int valint2;

void setup() {
    
    
    Particle.function("setleft", setleft);
    Particle.function("setright", setright);
    Particle.function("setallow", setallow);
    
    pinMode(D2, OUTPUT);
    pinMode(D3, OUTPUT);
    pinMode(D4, OUTPUT);
    pinMode(D5, OUTPUT);
    pinMode(D6, OUTPUT);
    
}

void loop() {

}

int setleft(String val) {
    valint1 = val.toInt();
    
    do1 = valint1;
    do2 = 512 - valint1;
    
    digitalWrite(leftmotor1, do1);
    digitalWrite(leftmotor2, do2);
    
    return 1;
}

int setright(String val) {
    valint2 = val.toInt();
    
    do3 = valint2;
    do4 = 512 - valint2;
    
    digitalWrite(rightmotor1, do3);
    digitalWrite(rightmotor2, do4);
    
    return 1;
}

int setallow(String val) {
    if (val = "true") {
        allow = 255;
    }
    else {
        allow = 0;
    }
    
    digitalWrite(enable, val);
    return 1;
}

When I compile this code It comes up with the error “conversion from ‘String’ to ‘bool’ is ambiguous”

Please help

Hi @NZRosto

Were you maybe thinking of analogWrite instead of digitalWrite? The digital pins can only take on 1 or 0 as a value.

If you want to use PWM outputs, like to a servo or similar, you should use analogWrite. Here is the doc:

https://docs.particle.io/reference/firmware/photon/#analogwrite-pwm-

1 Like

Also the line where this error occures (or rather the full error message with related notes and line numbers) would help.

But I guess the problem is here

And there are two errors.

  1. that single equal sign assigns "true" and doesn’t check for equality and
  2. I think you rather wanted to use int allow instead of String val in your digitalWrite() (or analogWrite()?)