arduino-libraries/Arduino_JSON

Serial examples with p5.js

tigoe opened this issue · 4 comments

tigoe commented

Not really an issue so much as a possible PR, but I did some tests with p5.js and p5.serialport. Short answer is that this library is great for Arduino-to-p5.js, a little more work for p5.js-to-Arduino. Comments, changes, etc. welcome.

@tigoe the Arduino_JSONSerialOut.ino example looks great!

For Arduino_JSONSerialIn.ino, would it make sense to have a fixed expected structure? Like something to trigger a digitalWrite(...) or analogWrite(...) a set of pins?

tigoe commented

I'm not totally sure I understand your question. Do you mean something like this?

  String incoming = Serial.readStringUntil('\n');
    // parse the string into a JSONVar object:
    JSONVar myObject = JSON.parse(incoming);
    int x = int(myObject["x"]);
    int y = int(myObject["y"]);
    // use the results:
    analogWrite(9, x);
    Serial.println("got x: " + String(x));

    analogWrite(10, y);
    Serial.println("got y: " + String(y));

Yes, something like that, however, instead of "x" and y for keys, maybe something like "led" and "motor"?

tigoe commented