Monday, December 14, 2009
codes
arduino:
piezo film as input sensor
piezo knock as output
questions:
1. how can we reverse the values
because right now the more you distort the film the closer to zero you get
2. we are getting a series of what we believe to be live values....we need to be able to store them
(I think it is best we do this in processing)
int analogPin = 3; // potentiometer wiper (middle terminal) connected to analog pin 3 // outside leads to ground and +5Vint ledPin = 9; // LED connected to digital pin 9
int val = 0; // variable to store the value read
void setup(){ Serial.begin(9600); // setup serial pinMode(ledPin, OUTPUT); // sets the pin as output}
void loop(){ val = analogRead(analogPin); // read the input pin Serial.println(val); // debug value
val = analogRead(analogPin); // read the input pin digitalWrite(ledPin, val / 4); // analogRead values go from 0 to 1023, analogWrite values from 0 to 255}
ok..... so on that note.....
how can we make this a bit louder
AND
in processing:
/** * Simple Read * * Read data from the serial port and change the color of a rectangle * when a switch connected to a Wiring or Arduino board is pressed and released. * This example works with the Wiring / Arduino program that follows below. */
import processing.serial.*;
Serial myPort; // Create object from Serial classint val; // Data received from the serial port
void setup() { size(600, 600); // I know that the first port in the serial list on my mac // is always my FTDI adaptor, so I open Serial.list()[0]. // On Windows machines, this generally opens COM1. // Open whatever port is the one you're using. String portName = Serial.list()[1]; myPort = new Serial(this, portName, 9600);}
void draw(){ if ( myPort.available() > 0) { // If data is available, val = myPort.read(); // read it and store it in val } background(255); // Set background to white if (val == 0) { // If the serial value is 0, fill(0); // set fill to black } else { // If the serial value is not 0, fill(204); // set fill to light gray } rect(50, 50, 100, 100);}
/*
// Wiring / Arduino Code// Code for sensing a switch status and writing the value to the serial port.
int switchPin = 4; // Switch connected to pin 4
void setup() { pinMode(switchPin, INPUT); // Set pin 0 as an input Serial.begin(9600); // Start serial communication at 9600 bps}
void loop() { if (digitalRead(switchPin) == HIGH) { // If switch is ON, Serial.print(1, BYTE); // send 1 to Processing } else { // If the switch is not ON, Serial.print(0, BYTE); // send 0 to Processing } delay(100); // Wait 100 milliseconds}
*/
this is reading the serial port of processing (with the same set up as seen above)
here the color of the serial port changes based on a value....i think this is a one time reading....
either that or...the values are reading too fast....
so
questions:
1. how can we slow down the values
2. how can we store the values.... i think using an array and/or witing a variable
3. how to interpret this data as audio output
- an echo...repeating the original input....(information repeated based on time variable)
or
- a tonal value....(a note produced at a specific frequency based on the value collected)
ie: the higher the value the higher the pitch (a direct relationship of the average values)
Post a Comment