...
- Tested Firmata example programs
Objectives:
- To understand what each statements does.
Descriptions:
Declaring an Arduino Firmata variable
Code Block language cpp linenumbers true // Firmata is using serial library, so you will need it to be included import processing.serial.*; // Also Firmata library needs to be included import cc.arduino.*; // Create an arduino object Arduino arduino; // If you need additional object (you have more than 1 arduinos connected) // Arduino arduino2; // You can name your own name or even make it array // Arduino arduinos[];
Create the Arduino Firmata object
Code Block language cpp linenumbers true // In setup because it only need to be created once // If you want to create it dynamically, you can also put it in draw() // But if you do this, you need some logic to prevent it from being created over and over again void setup() { // Your window setup stuff // ... // Prints out the available serial ports. println(Arduino.list()); // Modify this line, by changing the "0" to the index of the serial // port corresponding to your Arduino board (as it appears in the list // printed by the line above). arduino = new Arduino(this, Arduino.list()[0], 57600); // Alternatively, use the name of the serial port corresponding to your // Arduino (in double-quotes), as in the following line. // arduino = new Arduino(this, "/dev/tty.usbmodem621", 57600); // In addition, mac also can use arduino = new Arduino(this, Arduino.list()[5], 57600); // But the number is usually 5 for the first Arduino. When you run Arduino.list(), it will print out all the serial ports available. // Other codes // ... }