Arduino controll input command ON/OFF

My problem is that the laser can be turned on, but it can't be turned off. Sometimes it succeeds in ten attempts. I tried TFT display or serial control but still the same problem. Am I doing anything wrong? or is the hardware so busy that it can no longer accept further ID? Mega 2560, wemos mega wifi r3 atmega2560 esp8266.

void serialEvent3()
{
  while (Serial3.available())     
  {  
    char inChar = Serial3.read();      
 //   Serial.write(inChar);

    inString += inChar;  
    if (inChar == ']')
     {
        if (inString.indexOf("[ON]")>0)   { las_on = true;  }
       else 
        if (inString.indexOf("[OFF]")>0)  { las_on = false; }

       else

        if (inString.indexOf("[ON1]")>0)  {               }
       else 
        if (inString.indexOf("[OFF1]")>0) {               }
      
 // { Serial.println("Wrong command"); }
    
    //  inString = "";
    }
  }
}

void loop() 
{
  
if ( las_on == true  )
 { laser.setOffset(2048, 2048); laser.setScale(1); Drawing::drawObject(draw_point, sizeof(draw_point) /4); }

}

Welcome to the forum

What is sending the serial commands to the Arduino ?

We haven't seen the rest of your sketch, so who knows what it is doing when the laser is turned on ? Please post a complete sketch that illustrates the problem

Personally I have never seen the point the the SerialEvent functions. You might just as well use the available() function in loop() and do something if serial data arrives. I would also use strings rather than Strings, but that is another debate

Hello bigimot1
Take a view.

Have a nice day and enjoy coding in C++.

Here is the full code. My opinion is that the Controller is really very busy.

Which project on github is it supposed to be? LaserShow or LaserSpectrumAnalyzer? Neither of them seem to contain a function called serialEvent3().

There is no code to switch it off; may be an else needs to be added.

LaserShow.

I want to add that code. I want to control it through the application I make in Processing.

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