serialduplex.pde

来自「This is processing for java examples.」· PDE 代码 · 共 51 行

PDE
51
字号
/** * Serial Duplex  * by Tom Igoe.  *  * Sends a byte out the serial port when you type a key * listens for bytes received, and displays their value.  * This is just a quick application for testing serial data * in both directions.  */import processing.serial.*;Serial myPort;      // The serial portint whichKey = -1;  // Variable to hold keystoke valuesint inByte = -1;    // Incoming serial datavoid setup() {  size(400, 300);  // create a font with the third font available to the system:  PFont myFont = createFont(PFont.list()[2], 14);  textFont(myFont);  // List all the available serial ports:  println(Serial.list());  // I know that the first port in the serial list on my mac  // is always my  FTDI adaptor, so I open Serial.list()[0].  // In Windows, this usually opens COM1.  // Open whatever port is the one you're using.  String portName = Serial.list()[0];  myPort = new Serial(this, portName, 9600);}void draw() {  background(0);  text("Last Received: " + inByte, 10, 130);  text("Last Sent: " + whichKey, 10, 100);}void serialEvent(Serial myPort) {  inByte = myPort.read();}void keyPressed() {  // Send the keystroke out:  myPort.write(key);  whichKey = key;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?