Skip to content
Snippets Groups Projects
Commit 4c49a955 authored by Dorota Orlof's avatar Dorota Orlof
Browse files

adding processing files

parent 26ed5d2f
No related branches found
No related tags found
No related merge requests found
import processing.serial.*;
Serial doraPort; // Create object from Serial class
String val; // Data received from the serial port
boolean portFound = false;
void setup(){
println("Printing list of available serial ports...");
printArray(Serial.list());
String portName = "/dev/cu.usbserial-FT9P0907";
//String portName = "/dev/cu.Bluetooth-Incoming-Port";
String[] availPorts = Serial.list();
println("Looking for port " + portName + " in the list of available ports...");
for(int i = 0; i < availPorts.length; i=i+1){
if(availPorts[i].indexOf(portName) >= 0){
portFound = true;
break;
}
}
if(portFound == true){
println("Port found. Connecting...");
doraPort = new Serial(this, portName, 9600);
}else{
println("Port not found. Exiting...");
exit();
}
}
void draw() {
if ( doraPort.available() > 0) {
val = doraPort.readStringUntil('\n');
println(val);
}
}
import processing.serial.*;
Serial doraPort;
void setup()
{
size(200,200);
println(Serial.list());
String portName = Serial.list()[1];
println("Port use= "+portName);
doraPort = new Serial(this, portName, 9600);
}
void draw() {
/* if (mousePressed == true)
{
int val=doraPort.read();
println(val);
} else
{
doraPort.write('0');
}*/
String inBuffer = doraPort.readString();
if (inBuffer != null) {
println(inBuffer);
}
}
import processing.serial.*; //import the Serial library
Serial doraPort; //the Serial port object
String val;
// since we're doing serial handshaking,
// we need to check if we've heard from the microcontroller
boolean firstContact = false;
void setup() {
size(200, 200); //make our canvas 200 x 200 pixels big
// initialize your serial port and set the baud rate to 9600
doraPort = new Serial(this, Serial.list()[1], 9600);
doraPort.bufferUntil('\n');
}
void draw() {
//we can leave the draw method empty,
//because all our programming happens in the serialEvent (see below)
}
void serialEvent( Serial myPort) {
//put the incoming data into a String -
//the '\n' is our end delimiter indicating the end of a complete packet
val = myPort.readStringUntil('\n');
//make sure our data isn't empty before continuing
if (val != null) {
//trim whitespace and formatting characters (like carriage return)
val = trim(val);
println(val);
//look for our 'A' string to start the handshake
//if it's there, clear the buffer, and send a request for data
if (firstContact == false) {
if (val.equals("A")) {
myPort.clear();
firstContact = true;
myPort.write("A");
println("contact");
}
}
else { //if we've already established contact, keep getting and parsing data
println(val);
if (mousePressed == true)
{ //if we clicked in the window
myPort.write('1'); //send a 1
println("1");
}
// when you've parsed the data you have, ask for more:
myPort.write("A");
}
}
}
import processing.serial.*; //import the Serial library
Serial doraPort; //the Serial port object
String val;
int radius = 25;
// since we're doing serial handshaking,
// we need to check if we've heard from the microcontroller
boolean firstContact = false;
void setup() {
size(200, 200); //make our canvas 200 x 200 pixels big
// initialize your serial port and set the baud rate to 9600
doraPort = new Serial(this, Serial.list()[1], 9600);
doraPort.bufferUntil('\n');
}
void draw() {
clear();
// Draw the circle by using our globeal "radius" variable
ellipse(width / 2, height / 2, radius, radius);
}
void serialEvent( Serial myPort ) {
//put the incoming data into a String -
//the '\n' is our end delimiter indicating the end of a complete packet
val = myPort.readStringUntil('\n');
//make sure our data isn't empty before continuing
if (val != null) {
//trim whitespace and formatting characters (like carriage return)
val = trim(val);
println(val);
// Calculate the radius of the circle depending on the value
if(val.equals("zero")){
radius = 0;
}else if(val.equals("low")){
radius = 25;
}else if(val.equals("medium")){
radius = 50;
}else if(val.equals("high")){
radius = 75;
}
if (mousePressed == true)
{
float distFromCenter = dist(mouseX, mouseY, width/2, height/2);
//println("click distance from center: " + distFromCenter);
if(distFromCenter < radius){
//if we clicked in the window
myPort.write('1'); //send a 1
println("1");
}
}
// when you've parsed the data you have, ask for more:
//myPort.write("A");
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment