Wednesday, October 10, 2007

Vis

A visualization exercise:

I used a potentiometer to change the angles of an L-system.

Arduino Code as Follows: (uses pitch bend technique, partially copied from class examples, thank you Jamie Allen for the code)

#define header 224

int potPin = 0; // select the input pin for the potentiometer
int ledPin = 13; // select the pin for the LED
int val = 0; // variable to store the value coming from the sensor
int accVal = 0; // accumulation of a sum for averaging
int avg = 0; // average result
int howManyToAverage = 5; //number of individual values to average
int analogValLSB = 0; //least significant bit
int analogValMSB = 0; //most significant bit

void setup() {
pinMode(ledPin, OUTPUT); // declare the ledPin as an OUTPUT
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
}

void sendData3Byte(char cmd, char data1, char data2) {
Serial.print(cmd, BYTE);
Serial.print(data1, BYTE);
Serial.print(data2, BYTE);
}

void loop() {
int i;
digitalWrite(ledPin, HIGH); // sets the LED off
accVal = 0; // clear the accumulator
for (i=0; i val = analogRead(potPin); // read the value from the sensor
accVal = accVal + val;
delay(10);
}
avg = accVal/howManyToAverage;
analogValLSB = avg & 127; //Keep lower 7 bits bits, 0000000011111111 = 127
analogValMSB = (avg >> 7) ; //Need to shift the MSB into to the lower 7 bits
sendData3Byte(header, analogValLSB, analogValMSB); //Sends parsed data
delay(20); //give poor MIDI a chance!
digitalWrite(ledPin, LOW); //turn off light
}

0 Comments:

Post a Comment

<< Home