Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By martinayotte
#25411 Maybe ... It is not clear depending of the whole context of the application.
It derived from the usual philosphy of Arduino loop() should never be blocking, although your call to delay() will help the other task such Wifi to run, you won't be able to run other stuff in your own loop().

Let get back with my previous snippet of code :

Code: Select allvoid loop()
{
  if (Serial.available()) {
    int inByte = Serial.read();
    Serial.write(inByte);
    buf[i] = (char)inByte;
    if (inByte == '\r' or inByte == '\n') {
      buf[i] = 0;
      i = 0;
      Serial.print("echo = ");
      Serial.println(buf);
      if (strcmp(buf, "hello") == 0) {
        Serial.println("Hello !");
      }
      else if (strcmp(buf, "showip") == 0) {
        showIP(Serial);
      }
    }
    else
      i++;
  }
  // some other stuff to do in loop()
  if (blink_count >= blink_rate) {
    digitalWrite(led, HIGH);
    blink_count = 0;
  }
  if (blink_count == blink_rate / 2) {
    digitalWrite(led, LOW);
  }
  webserver.handleClient();
  delay(1);
  blink_count++;
}


You can see in the above code the last portion is doing additional tasks : First, a LED blink, even it you didn't have provide full line into your Serial transaction, LED still blink at a specific rate. Second, you add a webserver, but you wish that this server still provide responses even if your Serial transaction is not finished.

Hoping this giving you the idea about "pseudo-multithread" concept ...

Of course there are many other to do that, but the above is the Arduino concept.
BTW, for Serial handling, you can also look to SerialEvent (https://www.arduino.cc/en/Tutorial/SerialEvent) if you wish to fill the buffer as a background task, but still the main loop() will have to look at global flag.
User avatar
By Mmiscool
#25415 I come from the procedural programming world so this c++ thing is foreign to me.

I have actually been hard at work building a small basic interpreter to run on these modules.

This solved the problems I was having with the input command.

Variables can be strings or floats and usage is transparent to user.

SO far I have implemented the following commands
Code: Select allif {=,>,<,<>,} then {statement to be executed if true}
goto {label}
gosub {label}
return
{label:} (branch labels like in qbasic)
print {value or variable}
input {value or variable}
pinout {pin no} {value or var 1/0}
pinin {pin no} {var to place result 1/0}
let {variable} = {value or variable} {operator *,/,+,-,&} {value or variable}




Just started to integrate the interpreter with the code from here. Going to use this code to implement the web interface and programming environment.
http://www.john-lassen.de/index.php/pro ... -webconfig

Since those demos include the micro ajax code I believe I can have the basic interpreter running in the browser and implement the following commands
Code: Select all'place data in to the buffer to be sent to the browser when the wait statement is encountered
wprint {value or variable}

'Displays a textbox and submit button in the browser for user input. upon submission places the textbox contents in to the desired variable
winput {value or variable}

'Creates a button in the browser that when pressed will execute a goto statement to run a selected branch. Will be added to the browser data buffer and will be sent to the browser upon execution of wait command.
button {button text} {branch label to goto}

'Creates a text box in the browser with the contents of the variable placed in it. Upon clicking of any button the variables contents will be updated with any changes the user has made in the browser.
textbox {variable}

'To return wprint text to the browser along with buttons and text boxes and wait for user interaction. ie. button press
wait

'Clears the buffer that is to be sent to the browser
wcls



Once the web browser interface commands are complete I will be making a release for people to play with. Hopefully add some more gui widgets too once the ones listed above are complete.