1. Oktober 2012
I worked with the Piezo and light sensors, to experiment the communication between arduino and processing. I attached the piezo sensor to a metal sheet, this creates vibrations and when this vibrations reach a certain point it counts up, like a graphical counter, my first idea, and stil a work in process was to create a pedometer (step counter). Then I brought together with this graphical counter, a light sensor, that at first would change the background color, making it a bit more interactive and responsive to gestures. At the end i was experimenting a bit with sound too, you can hear a bit of noise, that should had been drums. This is what i used: and this a short video of what it does: https://vimeo.com/50532739 ARDUINO CODE: #define VIBRATION A0 #define LIGHT A1 int oldValue = 0; void setup() { Serial.begin(9600); } void loop() { int currValue = analogRead(VIBRATION); // Hier werden die Werte abgerufen int currValue2 = analogRead(LIGHT); // Hier werden die Werte abgerufen //currValue = 0.4*oldValue + 0.6*currValue; // Smoothing Funktion Serial.print(currValue); // Anzeigen der Werte über Serial Monitor Serial.print(currValue2); // Anzeigen der Werte über Serial Monitor Serial.print(','); Serial.println(); oldValue = currValue; // Hier wird der aktuelle Wert als oldValue gespeichert oldValue = currValue2; // Hier wird der aktuelle Wert als oldValue gespeichert } PROCESSING CODE: (STIL NEEDS SOME IMPROVEMENT) import ddf.minim.*; import processing.serial.*; import ddf.minim.signals.*; import javax.sound.sampled.*; Serial myPort; Minim minim1; AudioPlayer song1; //AudioSample snare; AudioOutput out1; int firstValue = 1023; int secondValue = 60; int widthShape = 40; int heightShape = 40; int counter = 0; int currShape = 0; void setup() { size(800, 800, P3D); myPort = new Serial(this, "/dev/tty.usbserial-A7005Ov4", 9600); minim1 = new Minim(this); // load BD.wav from the data folder out1 = minim1.getLineOut(Minim.STEREO); song1 = minim1.loadFile("drum_1.wav", 1024); //if ( song1 == null ) println("Didn't get kick!"); // load SD.wav from the data folder // snare = minim.loadSample("drum_2.wav", 2048); // if ( snare == null ) println("Didn't get snare!"); } void draw() { for (int y= 0; y< 20; y++) { for (int x= 0; x< 20; x++) { currShape = x+20*y; if (counter <= currShape) { fill(0); } else { fill(255); background(secondValue); } { beginShape(); vertex(x*widthShape, y*heightShape); vertex(x*widthShape+30, y*heightShape+30); vertex(x*widthShape+60, y*heightShape+60); vertex(x*widthShape, y*heightShape+60); endShape(); } } } if (firstValue < 980) { counter ++; } // if (secondValue > 100) // { // counter ++; // } if ( secondValue > 250) { song1.play(); } } //if ( secondValue > 200 ) snare.trigger(); void stop() { // always close Minim audio classes when you are done with them song1.close(); //snare.close(); minim1.stop(); out1.close(); super.stop(); } void serialEvent(Serial myPort) { if (myPort.available()> 0) { //println("Daten sind da"); String completeString = myPort.readStringUntil(10); if (completeString != null) // If there is valid data insode { trim(completeString); String seperateValues[] = split(completeString, ","); firstValue = int(seperateValues[0]); secondValue = int(seperateValues[1]); //vib = int(seperateValues[0]); } } }