/*
* Client
*/
import interfascia.*;
import processing.net.*;
// Font
PFont font;
// GUI textbox
GUIController c;
IFTextField t;
IFLabel l;
// Network client
Client cli;
String input;
void setup() {
size(800, 225);
background(255, 255, 255);
// Connect to the server's IP address and port
cli = new Client(this, "127.0.0.1", 12345); // server's IP and port
font = loadFont("ArialMT-18.vlw");
textFont(font, 18);
fill(0, 0, 0);
text("Send a melody using a string of notes [ c, d, e, f, g, a, b, C ] (e.g. cdedededefefef):", 27, 87);
c = new GUIController(this);
t = new IFTextField("Text Field", 25, 100, 750);
//l = new IFLabel("Type something and press return", 25, 70);
c.add(t);
//c.add(l);
t.addActionListener(this);
}
void draw() {
}
void actionPerformed(GUIEvent e) {
String msg;
// clear the screen
background(255, 255, 255);
textFont(font, 18);
text("Send a melody using a string of notes [ c, d, e, f, g, a, b, C ] (e.g. cdedededefefef):", 27, 87);
// if message was entered in textbox
if (e.getMessage().equals("Completed")) {
msg = t.getValue();
// feedback
textFont(font, 18);
fill(0, 0, 0);
text(msg + " sent successfully!", 27, 200);
// send melody to Processing interfaced w/ Arduino
cli.write(msg + "\n");
}
}
/*
* Server
*/
import processing.net.*;
import processing.serial.*;
Server s;
Client c;
String input;
int data[];
PFont font;
char val;
Serial port; // Create object from Serial class
void setup()
{
size(800, 225);
background(255, 255, 255);
//stroke(0);
// frameRate(5); // Slow it down a little
font = loadFont("ArialMT-18.vlw");
textFont(font, 18);
fill(0, 0, 0);
text("The melody sent was:", 27, 87);
s = new Server(this, 12345); // Start a simple server on a port
// Open the port that the board is connected to and use the same speed (9600 bps)
port = new Serial(this, 9600);
}
void draw()
{
// Receive data from client
c = s.available();
if (c != null) {
input = c.readString();
input = input.substring(0, input.indexOf("\n")); // Only up to the newline
// clear the screen
background(255, 255, 255);
textFont(font, 18);
text("The melody sent was:", 27, 87);
// send to serial
port.write(input);
fill(0, 0, 0);
text(input, 27, 107);
}
}