Fading and Mixing Colour LED’s Using a File on a Server

19 Nov

In a recent post I explained how to fade and mix colour LED’s using an Arduino Sketch. I am now going to use the exact same Sketch and LED’s but this time using a Processing Sketch as well I will scrape the RGB value off a .txt file on a server. Hopefully over the next few days I will then replace this .txt file with a PHP file to scrape the weather forecast off Yahoo! and convert it to an RGB value, then send this to the Arduino via my processing sketch.

Set up LED’s and upload Arduino Sketch the same way as this recent post

Below is the processing code I used (Thanks to todbot):


import processing.serial.*;

String portstr = “/dev/tty.usbserial-A7006T63”;
String urlstr = “http://mediacorkit.com/alan/ContentArduino.txt”;
int refreshTime = 10 * 1000;  // every 60 seconds;
int lastTime;

Serial port;
color c;

PFont font;

void setup() {

font = loadFont(“Futura-MediumItalic-48.vlw”);
textFont(font, 48);
text(urlstr, 10, height/2);

port = new Serial(this, portstr, 9600);

lastTime = 0;

void draw() {
background( c );

int n = (int)((refreshTime-(millis()-lastTime))/1000)+1;
println(“countdown to color: “+ n);
text( n, 10, 50);

if( millis() – lastTime >= refreshTime ) {
lastTime = millis();

void getWebColor() {
try {
URL url = new URL(urlstr);
URLConnection conn = url.openConnection();

BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null) {
System.out.println(”   content: “+inputLine);
if( inputLine.startsWith(“#”)) {
int ic = Integer.decode(inputLine).intValue();
c = color((ic>>16)&0xff,(ic>>8)&0xff,(ic>>0)&0xff);
String cs = Integer.toHexString(ic);
if(cs.length() == 1) cs = “00000”+cs;  // fix broken toHexString() behavior
if(cs.length() == 2) cs = “0000”+cs;
if(cs.length() == 3) cs = “000”+cs;
if(cs.length() == 4) cs = “00”+cs;
if(cs.length() == 5) cs = “0”+cs;
println(“parsed color #”+cs);
catch (Exception ex) {
System.out.println(“ERROR: “+ex.getMessage());



Make sure you change your serial port and the link to your own .txt file on a server.

After you upload the Arduino sketch run the Processing sketch and it will use the RGB value indicated in the .txt file to convert the LED’s.


My .txt file


Note: If like me, you are receiving a font error in Processing go to Tools/Create font and insert: Futura-MediumItalic-48




One Response to “Fading and Mixing Colour LED’s Using a File on a Server”


  1. Prototype « Ambient Knowledge - August 2, 2010

    […] ambient information about the weather forecast. I used the Arduino and Processing code from my earlier posts along with a PHP file used to scrape the information off the Yahoo! website. The Arduino receives […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: