Stap 12: verwerking
Zorg ervoor dat u de code via naar de Arduino verzenden, en dan laten we beginnen werken in verwerking. Kopieer en plak de onderstaande code in een bestand van de verwerking.
// Dimmer - sends bytes over a serial port // by David A. Mellis //This example code is in the public domain. import processing.serial.*; Serial port; int value = 0; void setup() { size(256, 150); println("Available serial ports:"); // if using Processing 2.1 or later, use Serial.printArray() println(Serial.list()); // Uses the first port in this list (number 0). Change this to // select the port corresponding to your Arduino board. The last // parameter (e.g. 9600) is the speed of the communication. It // has to correspond to the value passed to Serial.begin() in your // Arduino sketch. port = new Serial(this, Serial.list()[5], 9600); // If you know the name of the port used by the Arduino board, you // can specify it directly like this. //port = new Serial(this, "COM1", 9600); } void draw() { // draw a gradient from black to white fill(value); rect(25, 25, 50, 50); // write the current X-position of the mouse to the serial port as // a single byte port.write(value); } void keyPressed() { if (value == 0) { value = 255; } else { value = 0; } }