Some problem with setting PWM (Arduino nano)

Hello everyone,I’m a user from Taiwan ,so please forgive my poor English.
I want make a device that using 2 different PWM to control two diffrient LED by an app create by APP Inventor 2 slider.
Slider 1 use to control LED1,Slider 2 use to control LED2.
When I change slider 1 position , app send text"v",and then send number to setting PWM value,then send "e" to stop control,same logic as Slide1. change slider 2 position , app send text"s",and then send number to setting PWM value,then send "e" to stop control.
My problem is when I control one of the LED ,the other one LED also blink without control

Here is a part of my code↓

And here is my app screenshot↓

WHY?????

Images of code are worthless. And the code is incomplete. Please properly post the well formatted and complete code. Please read the forum guidelines to see how to properly post code and some information on making a good post.

Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in a code block.

One thing that I can tell you is that your method of receiving serial data is flawed. The serial input basics tutorial shows robust ways to send and receive serial data.

You assign 0 to Speed_value...

  Speed_value = 0;

and then you print Speed_value

        Serial.println(Speed_value);

Here is the Arduino Sketch you displayed... please post the complete Sketch.

  switch (var) {
    case 'v':
      Speed_value = 0;
      do {
        if (BT.available()) {
          Car_status = BT.read();
          Serial.println(Car_status);
          //當藍芽讀取到字元'e'時,就會跳出迴圈。
          if (Car_status == 'e') {
            Serial.println(Speed_value);
            break;
          } else
            //將傳送來的速度數值字元轉成整數。
            Speed_value - 10 * Speed_value + (Car_status - 48);
          analogWrite(MT_A, Speed_value);
        }
      } while (true);

    case 's':
      Speed_value = 0;
      do {
        if (BT.available()) {
          Car_status = BT.read();
          Serial.println(Car_status);
          //當藍芽讀取到字元'e'時,就會跳出迴圈。
          if (Car_status == 'e') {
            Serial.println(Speed_value);
            break;
          } else
            //將傳送來的速度數值字元轉成整數。
            Speed_value = 10 * Speed_value + (Car_status - 48);
          analogWrite(MT_B, Speed_value);
        }
      } while (true);
  }

*** I just notice, case 's:' is inside case 'v': so a close-brace "}" is missing immediately before case 's':

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.