Skip to content

Serial examples with p5.js #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
tigoe opened this issue Mar 31, 2019 · 4 comments
Open

Serial examples with p5.js #1

tigoe opened this issue Mar 31, 2019 · 4 comments

Comments

@tigoe
Copy link

tigoe commented Mar 31, 2019

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.

@sandeepmistry
Copy link
Contributor

@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
Copy link
Author

tigoe commented Apr 1, 2019

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

@sandeepmistry
Copy link
Contributor

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

@tigoe
Copy link
Author

tigoe commented Apr 1, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants