Created
April 16, 2014 16:27
-
-
Save LucyMatch/10902841 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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 | |
port.clear(); | |
// 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 | |
println(SensorInput); | |
//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