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.
sandeepmistry commented
@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));
sandeepmistry commented
Yes, something like that, however, instead of "x" and y for keys, maybe something like "led" and "motor"?
tigoe commented
Yes, that's a good idea.
…On Mon, Apr 1, 2019, 2:54 PM Sandeep Mistry ***@***.***> 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
<#1 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAXOnwrg5qtkWholiUGQj8QOcgv94mByks5vclX1gaJpZM4cUfwO>
.