Coding
There are two sketches that you'll be running: one Processing sketch, and one Arduino sketch. Here is the code for the Processing sketch. You can download it from www.makezine.com/getstartedarduino.
Example 6-1. Arduino networked lamp parts of the code are inspired by a blog post by Tod E. Kurt (todbot.com)
import processing.serial.*; String feed = "http://blog.makezine.com/index.xml"; int interval = 10; // retrieve feed every 60 seconds; int lastTime; // the last time we fetched the content int love = 0; int peace = 0; int arduino = 0; int light = 0; // light level measured by the lamp Serial port; color c; String cs; String buffer = ""; // Accumulates characters coming from Arduino PFont font; void setup() { size(640,480); frameRate(10); // we don't need fast updates font = loadFont("HelveticaNeue-Bold-32.vlw"); fill(255); textFont(font, 32); // IMPORTANT NOTE: // The first serial port retrieved by Serial.list() // should be your Arduino. If not, uncomment the next // line by deleting the // before it, and re-run the // sketch to see a list of serial ports. Then, change // the 0 in between [ and ] to the number of the port // that your Arduino is connected to. //println(Serial.list()); String arduinoPort = Serial.list()[0]; port = new Serial(this, arduinoPort, 9600); // connect to Arduino lastTime = 0; fetchData(); } void draw() { background( c ); int n = (interval - ((millis()-lastTime)/1000)); // Build a colour based on the 3 values c = color(peace, love, arduino); cs = ...
Get Getting Started with Arduino now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.