5,710
edits
Changes
→controlling from a Processing app
Save your modified Dimmer example, and revert back to the original dimmer code. We are now going to learn how to control the processor from the processing App. See the commented Processing code hidden at the end of the Dimmer program.
* In Processing, open a new sketch, and copy this code into it. Save this sketch as "arduino_test" or something like that. It should look like this:
[[Image:Arduino_serialtest_processing.png|300px]]
** Try running this sketch. When you do, it may give you an error about "COM1" or something of that sort. You need to tell the program what serial port your arduino is connected to. When the program runs, you will see a list of Serial ports, you can see mine in the picture above. On my comnputer, I see that my serial port is the "tty.usbserial-A900acnt", which is listed as device number 2 ([2]), so I go back into the processing code and change the line that says <code>port = new Serial</code>... to read <code>port = new Serial(this, Serial.list()[2], 9600);</code>
** Now if I run the sketch again, I know that it will be properly communicating with the Arduino. You will need to modify that line to reflect whichever serial port your arduino is connected to.