Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
//import the Serial library so can read from arudino input via serial communication
import processing.serial.*;
// the number 10 is ASCII for linefeed (end of serial.println),
//later we will look for this to break up individual messages
int end = 10;
String serial; // declare a new string called 'serial'
Serial port; // The serial port, this is a new instance of the Serial class (an Object)
int amebia_1_val = 0;
int amebia_2_val = 0;
int moonscape_val = 0;
void setup() {
//serial reading code
// initializing the object by assigning a port and baud rate (must match that of Arduino)
// you may need to change the number in [] to match which serial port your arduino is connected to
port = new Serial(this, Serial.list()[10], 9600);
// function from serial library that throws out the first reading,
// in case we started reading in the middle of a string from Arduino
// function that reads the string from serial port
// until a println and then assigns string to our string variable (called 'serial')
serial = port.readStringUntil(end);
// initially, the string will be null (empty)
serial = null;
void draw() {
//if there is data coming from the serial port read it/ store it
while (port.available() > 0) {
serial = port.readStringUntil(end);
//if the string is not empty, do this
if (serial != null) {
//capsense Input form Arduino, each value is seperated and split depending on the ','
//and then saved in seperate cells of the array so we can access each
String[] SensorInput = split(serial, ',');
//can help to print these to console at this point to check it's working
//convert the string inputs that are stored
//in the SensorInput array to ints so we can use them numerically
// int PRInt [];//Array that we will store the the Input from Arduino after we have converted it to int
// PRInt = int(SensorInput);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment