Final Project: The Kloud

11/30

 * I am beginning to realize the balloons are not going to generate adequate lift
 * As an alternative, I could use a weather balloon, although they are more expensive
 * Or, I scrap the idea of the balloons "lifting" the project, and imagine an installation where the are contained or helped aloft by a support structure -> ZIP TIEs


 * My real job today is figuring out Minim on Processing
 * That way I can begin to save & retrieve sound clips


 * I realized the other day that if I making the balloons "holders" for audio clips would be very cool


 * AH HA! Progress on the Audio Record/Playbck front:
 * Finally got a Processing Sketch that records and plays back audio!


 * But now, the problem of making this thing work with multiple clips, not just the last one recorded
 * HMMMMMM....


 * HA HA! Here's the most primitive albeit exciting Processing sketch for recording and playing back your audio:
 * And here's that code:
 * Sorry about the formatting, its just what wikis do to this stuff
 * Also note that this sketch requires the minim library

import ddf.minim.*;

Minim minim; AudioInput in; AudioRecorder recorder; AudioPlayer sample; int recordCount = 0;

void setup { size(512, 200, P2D); textMode(SCREEN); minim = new Minim(this);

// get a stereo line-in: sample buffer length of 2048 // default sample rate is 44100, default bit depth is 16 in = minim.getLineIn(Minim.STEREO, 2048); // create a recorder that will record from the input to the filename specified, using buffered recording // buffered recording means that all captured audio will be written into a sample buffer // then when save is called, the contents of the buffer will actually be written to a file // the file will be located in the sketch's root folder. //recorder = minim.createRecorder(in, "myrecording.wav", true); recorder = minim.createRecorder(in, "myrecording"+recordCount+".wav", true); textFont(createFont("SanSerif", 12)); }

void draw { background(0); stroke(255); // draw the waveforms // the values returned by left.get and right.get will be between -1 and 1, // so we need to scale them up to see the waveform for(int i = 0; i < in.bufferSize - 1; i++) {   line(i, 50 + in.left.get(i)*50, i+1, 50 + in.left.get(i+1)*50); line(i, 150 + in.right.get(i)*50, i+1, 150 + in.right.get(i+1)*50); } if ( recorder.isRecording ) {   text("Currently recording...", 5, 15); } else {   text("Not recording.", 5, 15); } }

void keyReleased { if ( key == 'r' ) {   // to indicate that you want to start or stop capturing audio data, you must call // beginRecord and endRecord on the AudioRecorder object. You can start and stop // as many times as you like, the audio data will be appended to the end of the buffer // (in the case of buffered recording) or to the end of the file (in the case of streamed recording). if ( recorder.isRecording ) {     recorder.endRecord; }   else {     recorder.beginRecord; } }  if ( key == 's' ) {   // we've filled the file out buffer, // now write it to the file we specified in createRecorder // in the case of buffered recording, if the buffer is large, // this will appear to freeze the sketch for sometime // in the case of streamed recording, // it will not freeze as the data is already in the file and all that is being done // is closing the file. // the method returns the recorded audio as an AudioRecording, // see the example AudioRecorder >> RecordAndPlayback for more about that recorder.save; recordCount++; recorder = minim.createRecorder(in, "myrecording"+recordCount+".wav", true); //sample = recorder.save; //sample.play; println("Done saving."); println("New Count ="); println(recordCount); } if( key == 'p') { // load a file, give the AudioPlayer buffers that are 1024 samples long // player = minim.loadFile("groove.mp3"); // load a file, give the AudioPlayer buffers that are 2048 samples long sample = minim.loadFile("myrecording"+(recordCount-1)+".wav"); // play the file //sample = recorder.save; sample.play; println("Play Called for Clip"+(recordCount-1)); } }

void stop { // always close Minim audio classes when you are done with them in.close; minim.stop; super.stop; }

12/2

 * Bruins game today -> Just discovered that if you go on Stub Hub day off you can get tix for like $8
 * MORE IMPORTANTLY, my LEDS finally came in
 * And now I know why they took so long -> They were coming in from Hong Kong (!!!)
 * Gonna start sautering them NOW


 * Also finally got the 15 foot USB cable so I can reach the cloud from the ground (it was only $4.89!)
 * So all the shipping is over (and that's gonna have to be it with the project due next week)


 * OK, here goes the sautering.


 * Turns out the 50 feet of wire I got at Home Depot is 18 gauge rather that 22 which is apparently what it needs to be
 * This means that I need to attach a little 22 gauge wire at the end of these things to make them look (and more importantly WORK) OK

12/6

 * Extensive work today and over the weekend
 * Built three "SMART" LEDs
 * Now Plugged them into the circuit, and I'm now programming them
 * Here's the code thru now (just for back-up purposes)

int ledPin1 = 13; int ledPin2 = 12; int ledPin3 = 11; int ledPin4 = 10; int ledPin5 = 9; int ledPin6 = 8; int ledPin7 = 7; int ledPin8 = 6; int ledPin9 = 5;

// the SMART LEDs that will read things int ledPinA = 4; int ledPinB = 3; int ledPinC = 2;

//Piezo sensor pins int sensorPinA = 0; int sensorPinB = 2; int sensorPinC = 5;

// Do we want debugging on serial out? 1 for yes, 0 for no int DEBUG = 1;

void setup { pinMode(ledPin1, OUTPUT); pinMode(ledPin2, OUTPUT); pinMode(ledPin3, OUTPUT); pinMode(ledPin4, OUTPUT); pinMode(ledPin5, OUTPUT); pinMode(ledPin6, OUTPUT); pinMode(ledPin7, OUTPUT); pinMode(ledPin8, OUTPUT); pinMode(ledPin9, OUTPUT); pinMode(ledPinA, OUTPUT); pinMode(ledPinB, OUTPUT); pinMode(ledPinC, OUTPUT); Serial.begin(9600); }

void loop { // read the value from the sensor: Serial.println("Top of Loop");

//These are the smart LEDS digitalWrite(ledPinA, HIGH); // LED A is Orange digitalWrite(ledPinB, HIGH); // LED B is Red digitalWrite(ledPinC, HIGH); // LED C is White

//Looking for change in the piezo state for Smart LED A int sensorValueA = analogRead(sensorPinA); //Serial.print(sensorValueA); //Serial.println("Value from A:"); delay(300); int sensorValue2A = analogRead(sensorPinA); //Serial.print(sensorValue2A); int changeValueA = sensorValueA - sensorValue2A;

if (abs(changeValueA) > 10) { allLEDSon; //delay(1000); //allLEDSoff; }

//Looking for change in the piezo state for Smart LED B int sensorValueB = analogRead(sensorPinB); //Serial.print(sensorValueB); //Serial.println("Value from B:"); delay(300); int sensorValue2B = analogRead(sensorPinB); //Serial.print(sensorValue2B); int changeValueB = sensorValueB - sensorValue2B;

if (abs(changeValueB) > 10) { //allLEDSon; //delay(1000); allLEDSoff; }

//Looking for change in the piezo state for Smart LED C int sensorValueC = analogRead(sensorPinC); Serial.print(sensorValueC); Serial.println("Value from C:"); delay(100); int sensorValue2C = analogRead(sensorPinC); Serial.print(sensorValue2C); int changeValueC = sensorValueC - sensorValue2C;

if (abs(changeValueC) > 10) { allLEDSon; delay(1000); allLEDSoff; }

if (Serial.available) { // read the most recent byte (which will be from 0 to 255): int ledNumber = 0; boolean l1 = false; boolean l2 = false; boolean l3 = false; boolean l4 = false; boolean l5 = false; boolean l6 = false; boolean l7 = false; boolean l8 = false; boolean l9 = false;

//For input from Processing Sketch (via keyboard) //See Kloud Controller sketch ledNumber = Serial.read; if (ledNumber == 1) {

digitalWrite(ledPin1, HIGH); }

if (ledNumber == 2) { digitalWrite(ledPin2, HIGH); }

if (ledNumber == 3) { digitalWrite(ledPin3, HIGH); }   if (ledNumber == 4) { digitalWrite(ledPin4, HIGH); }

if (ledNumber == 5) { digitalWrite(ledPin5, HIGH); }

if (ledNumber == 6) { digitalWrite(ledPin6, HIGH); }

if (ledNumber == 7) { digitalWrite(ledPin7, HIGH); }

if (ledNumber == 8) { digitalWrite(ledPin8, HIGH); }

if (ledNumber == 9) { digitalWrite(ledPin9, HIGH); } } }

void allLEDSon { //I'm sick of writing this over and over again, so here it is in  //a simple method digitalWrite(ledPin1, HIGH); digitalWrite(ledPin2, HIGH); digitalWrite(ledPin3, HIGH); digitalWrite(ledPin4, HIGH); digitalWrite(ledPin5, HIGH); digitalWrite(ledPin6, HIGH); digitalWrite(ledPin7, HIGH); digitalWrite(ledPin8, HIGH); digitalWrite(ledPin9, HIGH); }

void allLEDSoff { //I'm sick of writing this over and over again, so here it is in  //a simple method digitalWrite(ledPin1, LOW); digitalWrite(ledPin2, LOW); digitalWrite(ledPin3, LOW); digitalWrite(ledPin4, LOW); digitalWrite(ledPin5, LOW); digitalWrite(ledPin6, LOW); digitalWrite(ledPin7, LOW); digitalWrite(ledPin8, LOW); digitalWrite(ledPin9, LOW); }

12/8

 * PheW! Well, after a bout of illness (could have been Swine Flu, we don't know) I am back to coding into the kloud developing its capabilities.
 * I mapped out the LEDs which has enabled me to plot certain input patterns (like rain down)
 * Here's the code for those behaviors :

void allLEDSon { //I'm sick of writing this over and over again, so here it is in  //a simple method digitalWrite(ledPin1, HIGH); digitalWrite(ledPin2, HIGH); digitalWrite(ledPin3, HIGH); digitalWrite(ledPin4, HIGH); digitalWrite(ledPin5, HIGH); digitalWrite(ledPin6, HIGH); digitalWrite(ledPin7, HIGH); digitalWrite(ledPin8, HIGH); digitalWrite(ledPin9, HIGH); }

void allLEDSoff { //I'm sick of writing this over and over again, so here it is in  //a simple method digitalWrite(ledPin1, LOW); digitalWrite(ledPin2, LOW); digitalWrite(ledPin3, LOW); digitalWrite(ledPin4, LOW); digitalWrite(ledPin5, LOW); digitalWrite(ledPin6, LOW); digitalWrite(ledPin7, LOW); digitalWrite(ledPin8, LOW); digitalWrite(ledPin9, LOW); }

void rainDown { digitalWrite(ledPin1, HIGH); delay(100); digitalWrite(ledPin9, HIGH); delay(100); digitalWrite(ledPin1, LOW); digitalWrite(ledPin8, HIGH); delay(100); digitalWrite(ledPin9, LOW); digitalWrite(ledPin3, HIGH); delay(100); digitalWrite(ledPin8, LOW); digitalWrite(ledPin5, HIGH); delay(100); digitalWrite(ledPin3, LOW); digitalWrite(ledPin7, HIGH); delay(100); digitalWrite(ledPin5, LOW); digitalWrite(ledPin6, HIGH); delay(100); digitalWrite(ledPin7, LOW); digitalWrite(ledPin4, HIGH); delay(100); digitalWrite(ledPin6, LOW); digitalWrite(ledPin2, HIGH); delay(100); digitalWrite(ledPin4, LOW); delay(100); digitalWrite(ledPin2, LOW); }

void rainUp { //rain UP pattern digitalWrite(ledPin2, HIGH); delay(100); digitalWrite(ledPin4, HIGH); delay(100); digitalWrite(ledPin6, HIGH); digitalWrite(ledPin2, LOW); delay(100); digitalWrite(ledPin7, HIGH); digitalWrite(ledPin4, LOW); delay(100); digitalWrite(ledPin3, HIGH); digitalWrite(ledPin6, LOW); delay(100); digitalWrite(ledPin5, HIGH); digitalWrite(ledPin7, LOW); delay(100); digitalWrite(ledPin8, HIGH); digitalWrite(ledPin3, LOW); delay(100); digitalWrite(ledPin1, HIGH); digitalWrite(ledPin5, LOW); delay(100); digitalWrite(ledPin9, HIGH); digitalWrite(ledPin8, LOW); delay(100); digitalWrite(ledPin1, LOW); delay(100); digitalWrite(ledPin9, LOW); delay(100); }

void rainLeft { digitalWrite(ledPin1, HIGH); delay(100); digitalWrite(ledPin3, HIGH); delay(100); digitalWrite(ledPin6, HIGH); delay(100); digitalWrite(ledPin9, HIGH); delay(100); digitalWrite(ledPin5, HIGH); delay(100); digitalWrite(ledPin2, HIGH); delay(100); digitalWrite(ledPin8, HIGH); delay(100); digitalWrite(ledPin7, HIGH); delay(100); digitalWrite(ledPin4, HIGH); delay(100);

digitalWrite(ledPin1, LOW); delay(100); digitalWrite(ledPin3, LOW); delay(100); digitalWrite(ledPin6, LOW); delay(100); digitalWrite(ledPin9, LOW); delay(100); digitalWrite(ledPin5, LOW); delay(100); digitalWrite(ledPin2, LOW); delay(100); digitalWrite(ledPin8, LOW); delay(100); digitalWrite(ledPin7, LOW); delay(100); digitalWrite(ledPin4, LOW); delay(100); }

void rainRight {

digitalWrite(ledPin4, HIGH); delay(100); digitalWrite(ledPin7, HIGH); delay(100); digitalWrite(ledPin8, HIGH); delay(100); digitalWrite(ledPin2, HIGH); delay(100); digitalWrite(ledPin5, HIGH); delay(100); digitalWrite(ledPin9, HIGH); delay(100); digitalWrite(ledPin6, HIGH); delay(100); digitalWrite(ledPin3, HIGH); delay(100); digitalWrite(ledPin1, HIGH); delay(100);

digitalWrite(ledPin4, LOW); delay(100); digitalWrite(ledPin7, LOW); delay(100); digitalWrite(ledPin8, LOW); delay(100); digitalWrite(ledPin2, LOW); delay(100); digitalWrite(ledPin5, LOW); delay(100); digitalWrite(ledPin9, LOW); delay(100); digitalWrite(ledPin6, LOW); delay(100); digitalWrite(ledPin3, LOW); delay(100); digitalWrite(ledPin1, LOW); delay(100); }

Arduino speaks to Computer

 * Also got some code going that allows the cloud to send info BACK to the computer
 * Getting info FROM the computer (like keystrokes pressed to cue processes) has proved simple
 * But getting things going in the other direction initially proved a little more complicated.
 * But not too bad
 * Here's the code for the ARDUINO

Arduino Code
int ledPin1 = 13; int ledPin2 = 12; int ledPin3 = 11; int ledPin4 = 10; int ledPin5 = 9; int ledPin6 = 8; int ledPin7 = 7; int ledPin8 = 6; int ledPin9 = 5;

// the SMART LEDs that will read things int ledPinA = 4; int ledPinB = 3; int ledPinC = 2;

//Piezo sensor pins int sensorPinA = 0; int sensorPinB = 2; int sensorPinC = 5;

// Do we want debugging on serial out? 1 for yes, 0 for no int DEBUG = 1;

void setup { pinMode(ledPin1, OUTPUT); pinMode(ledPin2, OUTPUT); pinMode(ledPin3, OUTPUT); pinMode(ledPin4, OUTPUT); pinMode(ledPin5, OUTPUT); pinMode(ledPin6, OUTPUT); pinMode(ledPin7, OUTPUT); pinMode(ledPin8, OUTPUT); pinMode(ledPin9, OUTPUT); pinMode(ledPinA, OUTPUT); pinMode(ledPinB, OUTPUT); pinMode(ledPinC, OUTPUT); Serial.begin(9600); }

void loop { // read the value from the sensor:

//These are the smart LEDS digitalWrite(ledPinA, HIGH); // LED A is Orange digitalWrite(ledPinB, HIGH); // LED B is Red digitalWrite(ledPinC, HIGH); // LED C is White

//Looking for change in the piezo state for Smart LED A int sensorValueA = analogRead(sensorPinA); //Serial.print(sensorValueA); //Serial.println("Value from A:"); delay(300); int sensorValue2A = analogRead(sensorPinA); //Serial.print(sensorValue2A); int changeValueA = sensorValueA - sensorValue2A;

if (abs(changeValueA) > 10) { //allLEDSon; Serial.write(10); //delay(1000); //allLEDSoff; }

//Looking for change in the piezo state for Smart LED B int sensorValueB = analogRead(sensorPinB); //Serial.print(sensorValueB); //Serial.println("Value from B:"); delay(300); int sensorValue2B = analogRead(sensorPinB); //Serial.print(sensorValue2B); int changeValueB = sensorValueB - sensorValue2B;

if (abs(changeValueB) > 10) { //allLEDSon; //delay(1000); Serial.write(20); }

//Looking for change in the piezo state for Smart LED C int sensorValueC = analogRead(sensorPinC); delay(100); int sensorValue2C = analogRead(sensorPinC); int changeValueC = sensorValueC - sensorValue2C; if (abs(changeValueC) > 10) { Serial.write(30); } }

void allLEDSon { //I'm sick of writing this over and over again, so here it is in  //a simple method digitalWrite(ledPin1, HIGH); digitalWrite(ledPin2, HIGH); digitalWrite(ledPin3, HIGH); digitalWrite(ledPin4, HIGH); digitalWrite(ledPin5, HIGH); digitalWrite(ledPin6, HIGH); digitalWrite(ledPin7, HIGH); digitalWrite(ledPin8, HIGH); digitalWrite(ledPin9, HIGH); }

void allLEDSoff { //I'm sick of writing this over and over again, so here it is in  //a simple method digitalWrite(ledPin1, LOW); digitalWrite(ledPin2, LOW); digitalWrite(ledPin3, LOW); digitalWrite(ledPin4, LOW); digitalWrite(ledPin5, LOW); digitalWrite(ledPin6, LOW); digitalWrite(ledPin7, LOW); digitalWrite(ledPin8, LOW); digitalWrite(ledPin9, LOW); }

Processing Code
/* Kloud Controller Is designed to speak with an arduino configured for 9 (or more) LEDS and to turn them on and off based on keyboard inputs */ import processing.serial.*; Serial port; void setup { size(256, 150); println("Available serial ports:"); println(Serial.list); // Uses the first port in this list (number 0). Change this to // select the port corresponding to your Arduino board. The last // parameter (e.g. 9600) is the speed of the communication. It // has to correspond to the value passed to Serial.begin in your // Arduino sketch. port = new Serial(this, Serial.list[0], 9600);

} void draw { // draw a gradient from black to white for (int i = 0; i < 256; i++) { stroke(i); line(i, 0, i, 150); } // Send Keyboard Inputs to the Arduino for "Cloud Reading" purposes //

int val = port.read; //print(val); //println("next value"); if (val == 10) { println("my god ORANGE works!"); //This is a place to put in any methods you want }    if (val == 20) { println("my god RED works!"); //This is a place to put in any methods you want }    if (val == 30) { println("my god WHITE works!"); //This is a place to put in any methods you want } }

12/9

 * Thinking about using the Kloud interface to control the dansemiotic machine.
 * Shouldn't be all that hard (the dansemiotic machine just uses keyboard input) except for figuring out how to make an arduino talk to flash
 * The Firmata Library could be useful
 * Also, section on Flash & Arduino ->

12/9 (Later)

 * Still too sick to go to class, so I missed the Crit.
 * The only good news is that NOW I have time to make this really do something.
 * I am playing with the idea of having interaction from the Internet!


 * More explication to come


 * Probably going to use Twitter as an interface for people to control my LED sculpture from abroad
 * Using this Winterwell guy's JTwitter java library. Very Cool.
 * Here's the javadoc for it ->


 * Basically, I want people to control the sculpture above my bed by calling to the nine muses ->
 * Ok, looks like I MAY have something that will allow tweets to control the lights over my head. Which would be cool.
 * One problem conceptually, is that I'd like to have some sort of visual representation of what is happening.
 * This could be a live web feed. Which is cool and *might* be easiers
 * Or an image/upload using Twitpic (here's an example of how you do that)->


 * But in the mean time, here's the java code for a twitter control of this beast:

Twitter to Kloud Control

 * NOTE: this is JAVA code, that imports a few different libraries

package myPackage;

import processing.core.*; import processing.serial.*; import winterwell.jtwitter.*;

import java.util.ArrayList; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern;

public class LEDTwitter extends PApplet { //Twitter twitter = new Twitter("wakenbywonder","awakened"); Serial port; public void setup { // Make a Twitter object Twitter twitter = new Twitter("wakenbywonder","awakened"); // Print Daniel Winterstein's status //System.out.println(twitter.getStatus("zmccune")); // Set my status //twitter.setStatus("@awakenedbywonde Do I dare"); //ystem.out.println(twitter.getStatus("@awakenedbywonde")); if (!twitter.getReplies.isEmpty) { System.out.println("Found messages on Twitter:"); List l = twitter.getReplies; System.out.println(l.get(0)); }			 else{ System.out.println("No messages found"); }			 if (!twitter.getReplies.isEmpty) { System.out.println("Found messages on Twitter:"); List l = twitter.getReplies; System.out.println(l.get(0)); extractSentences(l.get(0).toString.toLowerCase); }			 else{ System.out.println("No messages found"); }	}	public void draw { }	public List extractSentences(String pageContents) { ArrayList ar = new ArrayList; //patterns for each of the muses Pattern clio = Pattern.compile("clio"); Matcher m = clio.matcher(pageContents); while (m.find) { //			 ar.add(m.group); // return pageContents; System.out.print(m.group); System.out.println("Arduino LED 1 illuminated!"); }		 Pattern thalia = Pattern.compile("thalia"); Matcher m2 = thalia.matcher(pageContents); while (m2.find) { //			 ar.add(m2.group); // return pageContents; System.out.print(m2.group); System.out.println("Arduino LED 2 illuminated!"); }		 Pattern calliope = Pattern.compile("calliope"); Matcher m3 = calliope.matcher(pageContents); while (m3.find) { //			 ar.add(m3.group); // return pageContents; System.out.print(m3.group); System.out.println("Arduino LED 3 illuminated!"); }		 Pattern erato = Pattern.compile("erato"); Matcher m4 = erato.matcher(pageContents); while (m4.find) { //			 ar.add(m4.group); // return pageContents; System.out.print(m4.group); System.out.println("Arduino LED 4 illuminated!"); }		 Pattern eutrepe = Pattern.compile("eutrepe"); Matcher m5 = eutrepe.matcher(pageContents); while (m5.find) { //			 ar.add(m5.group); // return pageContents; System.out.print(m5.group); System.out.println("Arduino LED 5 illuminated!"); }		 Pattern melpomene = Pattern.compile("melpomene"); Matcher m6 = melpomene.matcher(pageContents); while (m6.find) { //			 ar.add(m6.group); // return pageContents; System.out.print(m6.group); System.out.println("Arduino LED 6 illuminated!"); }		 Pattern polyhymnia = Pattern.compile("polyhymnia"); Matcher m7 = polyhymnia.matcher(pageContents); while (m7.find) { //			 ar.add(m7.group); // return pageContents; System.out.print(m7.group); System.out.println("Arduino LED 7 illuminated!"); }		 Pattern terpischore = Pattern.compile("terpischore"); Matcher m8 = terpischore.matcher(pageContents); while (m8.find) { //			 ar.add(m8.group); // return pageContents; System.out.print(m8.group); System.out.println("Arduino LED 8 illuminated!"); }		 Pattern urania = Pattern.compile("calliope"); Matcher m9 = urania.matcher(pageContents); while (m9.find) { //			 ar.add(m9.group); // return pageContents; System.out.print(m9.group); System.out.println("Arduino LED 9 illuminated!"); }		return ar; } }


 * All I needed to do was add Serial functionality
 * That was it !
 * And of course, that's where the fucking thing exploded. So hear we go again. Back to playing around trying to get it to work
 * The only good news, is that here's a discussion thread on my exact problem : - >