Arduino_JSON icon indicating copy to clipboard operation
Arduino_JSON copied to clipboard

Serial examples with p5.js

Open tigoe opened this issue 6 years ago • 4 comments

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 avatar Mar 31 '19 19:03 tigoe

@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?

sandeepmistry avatar Apr 01 '19 14:04 sandeepmistry

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));

tigoe avatar Apr 01 '19 16:04 tigoe

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

sandeepmistry avatar Apr 01 '19 18:04 sandeepmistry

Yes, that's a good idea.

On Mon, Apr 1, 2019, 2:54 PM Sandeep Mistry [email protected] wrote:

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

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/arduino-libraries/Arduino_JSON/issues/1#issuecomment-478701338, or mute the thread https://github.com/notifications/unsubscribe-auth/AAXOnwrg5qtkWholiUGQj8QOcgv94mByks5vclX1gaJpZM4cUfwO .

tigoe avatar Apr 01 '19 19:04 tigoe