document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. import processing.serial.*;
  2.  
  3. Serial myPort; // The serial port
  4. int whichKey = -1; // Variable to hold keystoke values
  5. int inByte = -1; // Incoming serial data
  6.  
  7. void setup() {
  8. size(400, 300);
  9. PFont myFont = createFont(PFont.list()[0], 24);
  10. textFont(myFont);
  11.  
  12.  
  13. printArray(Serial.list()); // List all the available serial ports:
  14.  
  15. String portName = Serial.list()[0];
  16. myPort = new Serial(this, portName, 9600);
  17. }
  18.  
  19. void draw() {
  20. background(0);
  21. text("Last Received: " + inByte, 10, 130);
  22. text("Last Sent: " + whichKey, 10, 100);
  23. }
  24.  
  25. void serialEvent(Serial myPort) {
  26. inByte = myPort.read();
  27. }
  28.  
  29. void keyPressed() {
  30. myPort.write(key); // Send the keystroke to my serial port
  31. whichKey = key;
  32. }
');