Serial examples with p5.js
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?
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"?
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 .