RGBPLAY

AvatarLED play!

Working Key Sketch



import hypermedia.net.*;
import processing.serial.*;
import cc.arduino.*;

Arduino arduino; //define the serial port
int ledPin = 13; //Connect an LED to digital pin 13

UDP udp; // define the UDP object

void setup() {

udp = new UDP( this, 11000 );
udp.listen( true );
println(Arduino.list());
arduino = new Arduino(this, Arduino.list()[1]);
arduino.pinMode(ledPin, Arduino.OUTPUT);

}

void draw() {
;
}

void keyPressed() {

String message = str( key );
String ip = "localhost";
int port = 11000;

message = message+";\n";
udp.send( message, ip, port );

}

void receive( byte[] data, String ip, int port ) {
data = subset(data, 0, data.length);
String message = new String( data );

if (message.startsWith("h")){
//println( "receive: \""+message+"\" from "+ip+" on port "+port+": LED ON" );
arduino.digitalWrite(ledPin, Arduino.HIGH);
}
else {
//println( "String Doesn't Match 'H': LED OFF");
arduino.digitalWrite(ledPin, Arduino.LOW);
}
}

0 comments: