Arduino and LEDs showing results of an internet search

This is a quick write-up of an Arduino art consulting job I always intended to find photographs of, to no avail. Given the lack of lovely graphics to encourage your eye down the page, I'll keep it brief.

The internet is growing, but as it grows, it is falling apart. This was the message of a communication designer, who came to me asking for an Arduino script and circuit that would fit inside a modem case, and flash LEDs upon receiving an output from other programs, which I didn’t write. The other program was set to search the internet for dead links and other signs of network degradation. It kicked out a file containing the number discovered of each of four types of errors. My component would flash a different light for each type, each time a new fault was discovered in the web.

The major challenges of this project were twofold:

  1. I expected the other programs to find errors one at a time, meaning that any change in the output file would be translateable into a single flash of the LED, for one error. In fact, they tended to find a whole bunch of errors at once, and then find nothing for a few minutes. I didn't want the program to sit still while performing a loop to blink an LED 100+ times, only to miss new changes to the other program's output. Nor did I want it to blink only once regardless of the number of new errors discovered.
  2. Strings, arrays and ints are tricky

Running several loops at the same time

To represent the scale of the errors discovered, I needed to do some basic but instructive jiggery-pokery with the code:
if (diffa > 0 && (currentMillis - aMillis > 100)) { aMillis = currentMillis; // if the LED is off turn it on and vice-versa: if (aState == false){ aState = true; arduino.digitalWrite(aPin, Arduino.HIGH); } else { aState = false; arduino.digitalWrite(aPin, Arduino.LOW); diffa = diffa-1; // Enable progress to the next blink of this set } }
For each output (this extract is for the error type and light designated 'a') the 'diff' is generated by recognising changes to the output file. An LED is blinked once every 100 millis to represent each of the new errors represented by the 'diff.' This acts like a for loop, but works in parallel to similar loops for other error types and LEDs.

Strings, integers and arrays

This is rudimentary stuff, but it was new to me, so in the interests of sharing the learning experience, here are some useful facts to bear in mind when reading and comparing outputs from other programs:
  1. Files are loaded as arrays. Each line of the file is a new line in the array, each character a new cell.
  2. If instructed to read these lines individually, they will be loaded as strings. Strings cannot be compared mathematically.
  3. Strings can in turn be loaded as integers for mathematical operation.
It sounds simple - and it is - but it took hours to figure out why the Processing sketch wouldn't play with a .txt file. In the end, the solution was fairly tidy:
count = loadStrings("/Users/zoya/Documents/paid_work/degradation/ErrorCount.txt");

a = Integer.parseInt(count[0]); b = Integer.parseInt(count[1]); c = Integer.parseInt(count[2]); d = Integer.parseInt(count[3]);