Justin Kaput's log
Final
Final Project Idea - Drum Gloves
My mom sent me this link (http://www.chris3000.com/portfolio/megatap-3000/) to a website that has plans for MegaTap 3000, which is a set of drum gloves that use pressure sensors on the fingertips to play drum sounds. My idea would be to create my own drum gloves and have them play a set of drums in a processing sketch. I would use different fingers as different elements of the drum kit, and could possibly (no promises) play part of a song when it's all finished. I think this would be really cool to play with and could be elaborated later into possibly guitar and/or bass gloves. I would try to make them now, but I don't think I can teach myself guitar and have it ready to go in a week. |
Assignment 11.2
This one isn't very exciting, but I figured I'd better turn it in and get started on my final. It turns two motors one way when the cursor is on the white rectangle in the processing window and the other way when the cursor is on the red rectangle. Here are my codes:
Arduino:
int val; // set up variables
const int motor1Pin1 = 4; const int motor1Pin2 = 3; const int motor2Pin1 = 5; const int motor2Pin2 = 6; const int enable1Pin = 8; const int enable2Pin = 9; void setup() {
pinMode(motor1Pin1, OUTPUT); // set motor pins to output pinMode(motor1Pin2, OUTPUT); pinMode(motor2Pin1, OUTPUT); pinMode(motor2Pin2, OUTPUT); pinMode(enable1Pin, OUTPUT); pinMode(enable2Pin, OUTPUT); digitalWrite(enable1Pin, HIGH); // set enable pins to high digitalWrite(enable2Pin, HIGH); Serial.begin(9600); // begin serial communication at 9600 bps } void loop() {
if(Serial.available()) { // if data is available, val = Serial.read(); // read it and store it in val } if (val == 1) { // if val is this, digitalWrite(motor1Pin1, HIGH); // turn the motors one way digitalWrite(motor1Pin2, LOW); digitalWrite(motor2Pin1, HIGH); digitalWrite(motor2Pin2, LOW); } if (val == 2) { // if val is this, digitalWrite(motor1Pin1, LOW); // turn the motors the other way digitalWrite(motor1Pin2, HIGH); digitalWrite(motor2Pin1, LOW); digitalWrite(motor2Pin2, HIGH); } } Processing:
import processing.serial.*; //import the processing serial library
Serial myPort; // set up variables int val; void setup() {
size(200, 200); // set screen size myPort = new Serial(this, Serial.list()[0], 9600); // begin serial communication at 9600 bps background(0); // set background color } void draw() {
val = mouseX; // set val equal to the mouse position in the x plain if(val <= 100) { // if val is less than or equal to 100, myPort.write(1); // write 1 to the serial port println(1); // and print 1 } if(val >= 101) { // if val is greater than or equal to 101, myPort.write(2); // write 2 to the serial port println(2); // and print 2 } stroke(255); // set stroke color fill(255); // set fill color rect(0, 0, width/2, height); // draw a rectangle equal to half the window fill(225, 0, 0); stroke(225, 0, 0); rect(width/2, 0, width, height); } and here's a Fritzing pic of my circuit:
|
Assignment 10.3
I used keys on the keyboard to light up the RGB LED different colors when different keys are pressed. The keys used are "r" for the red LED, "g" for the green LED, "b" for the blue LED, and "y", "c", "m", and "w" to light up combinations of the three LEDs to produce yellow, cyan, magenta, and white, respectively. When the key is pressed in the Processing window, the background color is changed also. Here are my codes:
Arduino
int red = 11; // set up variables
int green = 3; int blue = 9; int val; void setup() {
Serial.begin(9600); // begin serial communication at 9600 bps } void loop() {
if (Serial.available()) { // if serial is available, val = Serial.read(); // read it and store it in val } if (val == 'r') { // if val is this, analogWrite(red, 255); // light up this LED and delay(25); // delay for 25 millisceonds } else if (val == 'g') { analogWrite(green, 255); delay(25); } else if (val == 'b') { analogWrite(blue, 255); delay(25); } else if (val == 'y') { analogWrite(red, 255); analogWrite(green, 255); delay(25); } else if (val == 'c') { analogWrite(green, 255); analogWrite(blue, 255); delay(25); } else if (val == 'm') { analogWrite(red, 255); analogWrite(blue, 255); delay(25); } else if (val == 'w') { analogWrite(red, 255); analogWrite(green, 255); analogWrite(blue, 255); delay(25); } else if (val == 'n') { analogWrite(red, 0); analogWrite(green, 0); analogWrite(blue, 0); } } Processing
import processing.serial.*; // import processing serial library
Serial myPort; // set up variable void setup() { size(250, 250); // sets screen size to 250 x 250 pixels myPort = new Serial(this, Serial.list()[0], 9600); // sets up serial port and begins serial communication at 9600 bps } void draw() {
background(0); // sets background color to black } void keyPressed() {
if (key == 'r') { // if key pressed is this key: myPort.write('r'); // write r to the serial port, background(255, 0, 0); // change the background color, and delay(15); // delay for 15 milliseconds } if (key == 'g') { myPort.write('g'); background(0, 255, 0); delay(15); } if (key == 'b') { myPort.write('b'); background(0, 0, 255); delay(15); } if (key == 'y') { myPort.write('y'); background(255, 255, 0); delay(15); } if (key == 'c') { myPort.write('c'); background(0, 255, 255); delay(15); } if (key == 'm') { myPort.write('m'); background(255, 0, 255); delay(15); } if (key == 'w') { myPort.write('w'); background(255); delay(15); } if (key == 'x') { // I have no idea why I need this, but myPort.write('n'); // if I don't have it the last color will // stay on until the program is reset } else { // if any other key is pressed, myPort.write('n'); // write n to the serial port } } I tried to make it so that pressing a combination of keys would light up the same combination of LEDs, but it would either not turn off when the keys were released or would only light up one of the LEDs. |
Assignment 10.2
For this sketch I used the X position of the cursor in the Processing window to control both the brightness of an LED connected to pin 9 of my Arduino and the opacity of a rectangle in the Processing window. Here are my codes:
Arduino:
int val = 0;
int ledPin = 9; void setup() {
Serial.begin(9600); } void loop() {
if (Serial.available()) { val = Serial.read(); } analogWrite(ledPin, val); delay(20); } and Processing:
import processing.serial.*;
Serial myPort; int valX; int valY; void setup() {
size(255, 255); String portName = Serial.list()[0]; myPort = new Serial(this, portName, 9600); } void draw() {
background(0); valX = mouseX; myPort.write(valX); println(valX); delay(20); fill(0, 255, 0, valX); rect(0, 0, 255, 255); } I tried to use the Y position of the cursor to control another LED, but I don't know how to split the String of values sent from Processing to Arduino.
|
Assignment 9.3
Here I made a program that plays different techno loops when different keys on the keyboard are pressed. The keys used are d, f, g, h, j, and k. The loops can be played all at once or one at a time.
Processing code:
import ddf.minim.*; // include the minim library
AudioPlayer intro; // declare variables
AudioPlayer stabs; AudioPlayer layers; AudioPlayer chords; AudioPlayer aliens; AudioPlayer playstation; Minim minim; void setup()
{ // set screen size size(512, 200, P2D); minim = new Minim(this); // load a file, give the AudioPlayer buffers that are 2048 samples long intro = minim.loadFile("Trance_Intro.wav", 2048); stabs = minim.loadFile("Trance_Synth_Stabs.wav", 2048); layers = minim.loadFile("Trance_Layers_2.wav", 2048); chords = minim.loadFile("Rave_Chords.wav", 2048); aliens = minim.loadFile("Nine_Inch_Aliens.wav", 2048); playstation = minim.loadFile("Playstation.wav", 2048); } void draw()
{ background(0); // set background color stroke(255); // set the stroke color // 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 < intro.left.size()-1; i++) { stroke(0, i, 0); // change each line's color to spice things up a bit line(i, 50 + intro.left.get(i)*50, i+1, 50 + intro.left.get(i+1)*50); line(i, 150 + intro.right.get(i)*50, i+1, 150 + intro.right.get(i+1)*50); } for(int u = 0; u < stabs.left.size()-1; u++) { stroke(u, 0, 0); line(u, 50 + stabs.left.get(u)*50, u+1, 50 + stabs.left.get(u+1)*50); line(u, 150 + stabs.right.get(u)*50, u+1, 150 + stabs.right.get(u+1)*50); } for(int y = 0; y < layers.left.size()-1; y++) { stroke(0, 0, y); line(y, 50 + layers.left.get(y)*50, y+1, 50 + layers.left.get(y+1)*50); line(y, 150 + layers.right.get(y)*50, y+1, 150 + layers.right.get(y+1)*50); } for(int t = 0; t < chords.left.size()-1; t++) { stroke(t, 0, t); line(t, 50 + chords.left.get(t)*50, t+1, 50 + chords.left.get(t+1)*50); line(t, 150 + chords.right.get(t)*50, t+1, 150 + chords.right.get(t+1)*50); } for(int r = 0; r < aliens.left.size()-1; r++) { stroke(0, r, r); line(r, 50 + aliens.left.get(r)*50, r+1, 50 + aliens.left.get(r+1)*50); line(r, 150 + aliens.right.get(r)*50, r+1, 150 + aliens.right.get(r+1)*50); } for(int e = 0; e < playstation.left.size()-1; e++) { stroke(e, e, 0); line(e, 50 + playstation.left.get(e)*50, e+1, 50 + playstation.left.get(e+1)*50); line(e, 150 + playstation.right.get(e)*50, e+1, 150 + playstation.right.get(e+1)*50); } } void keyPressed() {
if(key == 'k') { // if key pressed is this, intro = minim.loadFile("Trance_Intro.wav", 2048); // reload the file and intro.play(); // play it } if(key == 'j') { stabs = minim.loadFile("Trance_Synth_Stabs.wav", 2048); stabs.play(); } if(key == 'h') { layers = minim.loadFile("Trance_Layers_2.wav", 2048); layers.play(); } if(key == 'g') { chords = minim.loadFile("Rave_Chords.wav", 2048); chords.play(); } if(key == 'f') { aliens = minim.loadFile("Nine_Inch_Aliens.wav", 2048); aliens.play(); } if(key == 'd') { // this one was taken from Eiffel 65's song "My Console" on their album Europop playstation = minim.loadFile("Playstation.wav", 2048); playstation.play(); } } void stop()
{ // always close Minim audio classes when you are done with them intro.close(); stabs.close(); layers.close(); chords.close(); aliens.close(); minim.stop(); super.stop(); } I borrowed the playstation loop from one of my old CDs just for fun. |
Assignment 10.1
For this one I used a potentiometer connected to analog pin 1 to control the brightness of an LED connected to digital pin 9.
Here's my code:
int val = 0;
int ledPin = 9; int potPin = 1; void setup() {
//twiddle your thumbs } void loop() {
val = analogRead(potPin); val = map(val, 0, 1023, 0, 225); analogWrite(ledPin, val); delay(30); } Here's a Fritzing pic of my circuit:
|
Assignment 9.2
This circuit uses four push buttons connected to pins 4-7 on the Arduino to control sound in Processing. For each button pressed, a different drum sound is played in Processing. For example: when the button connected to pin 4 is pressed, a cowbell sound is played. The sounds can also be played by pressing keys k, j, h, and g.
Arduino code:
int switchPin1 = 4; // declares variables
int switchPin2 = 5; int switchPin3 = 6; int switchPin4 = 7; void setup() {
Serial.begin(9600); // begin serial communication at 9600 bps pinMode(switchPin1, INPUT); // set switchPins to input pinMode(switchPin2, INPUT); pinMode(switchPin3, INPUT); pinMode(switchPin4, INPUT); } void loop() {
if(digitalRead(switchPin1) == HIGH) { // if button is pressed Serial.print(1, DEC); // print this number delay(100); // and delay for 100 milliseconds } else if(digitalRead(switchPin2) == HIGH) { Serial.print(2, DEC); delay(100); } else if(digitalRead(switchPin3) == HIGH) { Serial.print(3, DEC); delay(100); } else if(digitalRead(switchPin4) == HIGH) { Serial.print(4, DEC); delay(100); } } Processing code:
import processing.serial.*; // import libraries
import ddf.minim.*; Minim minim; // declare variables
AudioSample cowbell; AudioSample bass; AudioSample kick; AudioSample snare; Serial myPort; void setup()
{ // sets screen size size(512, 200, P2D); // always start Minim before you do anything with it minim = new Minim(this); // load file from the data folder, with a 512 sample buffer cowbell = minim.loadSample("Cowbell.mp3"); bass = minim.loadSample("Bass.wav"); kick = minim.loadSample("Kick.wav"); snare = minim.loadSample("Snare.wav"); // sets port to read from String portName = Serial.list()[0]; myPort = new Serial(this, Serial.list()[0], 9600); } void draw()
{ int val = 0; // resets value every time draw is run background(0); // sets background color stroke(255); // sets stroke color // use the mix buffer to draw the waveforms. // because these are MONO files, we could have used the left or right buffers and got the same data for (int i = 0; i < cowbell.bufferSize() - 1; i++) { line(i, 100 - cowbell.left.get(i)*50, i+1, 100 - cowbell.left.get(i+1)*50); } for (int u = 0; u < bass.bufferSize() - 1; u++) { line(u, 100 - bass.left.get(u)*50, u+1, 100 - bass.left.get(u+1)*50); } for (int y = 0; y < kick.bufferSize() - 1; y++) { line(y, 100 - kick.left.get(y)*50, y+1, 100 - kick.left.get(y+1)*50); } for (int t = 0; t < snare.bufferSize() - 1; t++) { line(t, 100 - snare.left.get(t)*50, t+1, 100 - snare.left.get(t+1)*50); } if (myPort.available() > 0) { // if there is data available to read, val = myPort.read(); // read it and store it in val println(val); // print the value of val } if (val == 49 ) cowbell.trigger(); // if val is this, play the sound if (val == 50 ) bass.trigger(); if (val == 51 ) kick.trigger(); if (val == 52 ) snare.trigger(); } void keyPressed()
{ if ( key == 'k' ) cowbell.trigger(); // if this key is pressed, play this sound if ( key == 'j' ) bass.trigger(); if ( key == 'h' ) kick.trigger(); if ( key == 'g' ) snare.trigger(); } void stop()
{ // always close Minim audio classes when you are done with them cowbell.close(); bass.close(); kick.close(); snare.close(); minim.stop(); super.stop(); } This one took me a while to figure out. It took me a couple tries to figure out where exactly to save the sound clips so that they could be read in the program, and then when i got that worked out the sound would repeat until another button was pressed, and then that sound would repeat. I solved that by resetting val every time the void draw function was run. I still have no idea where the values change from 1-4 to 49-52, but I got the program working and I didn't want to mess it up. A Fritzing picture of my circuit is attached. |
Assignment 9.1
I built a completely new circuit for this one. I got rid of the push buttons and added two potentiometers attached to analog pins 0 and 4 so that I could get two analog values to control the frequency(pitch) and amplitude(volume).
Arduino:
int potPin1 = 0; // set up variables
int potPin2 = 4; int val1 = 0; int val2 = 0; void setup() {
Serial.begin(9600); // begin serial communication at 9600 bps } void loop() {
val1 = analogRead(potPin1); // read potPin value and store in val1 val1 = map(val1, 0, 1023, 0, 4978); // adjust values val2 = analogRead(potPin2);
val2 = map(val2, 0, 1023, 0, 4978); Serial.print(val1, DEC); // print values and separate with a comma
Serial.print(','); Serial.println(val2, DEC); } Processing:
import processing.serial.*; // import libraries
import ddf.minim.*; import ddf.minim.signals.*; Minim minim; // set up variables AudioOutput out; SineWave sine; Serial myPort; float freq; float amp; void setup() {
size(400, 220, P2D); // sets window size minim = new Minim(this); // get a line out from Minim with default bufferSize, sample rate, and bit depth out = minim.getLineOut(Minim.STEREO); // create a sine wave oscillator, set to value of freq, value of amp, sample rate from line out sine = new SineWave(freq, amp, out.sampleRate()); // set the portamento speed on the oscillator to 200 milliseconds sine.portamento(200); // add the oscillator to the line out out.addSignal(sine); // declares myPort and begins serial communication at 9600 bps myPort = new Serial(this, Serial.list()[0], 9600); // store values from myPort in a buffer until value is reached myPort.bufferUntil('\n'); } void draw() {
background(0); // sets background color stroke(255); // sets stroke color // draw the waveforms for(int i = 0; i < out.bufferSize() - 1; i++) { float x1 = map(i, 0, out.bufferSize(), 0, width); float x2 = map(i+1, 0, out.bufferSize(), 0, width); line(x1, 50 + out.left.get(i)*50, x2, 50 + out.left.get(i+1)*50); line(x1, 150 + out.right.get(i)*50, x2, 150 + out.right.get(i+1)*50); } } void serialEvent (Serial myPort) {
// read string and store it in a buffer until value is reached String myString = myPort.readStringUntil('\n'); // if there is something in myString if(myString != null) { // split it at the comma myString = trim(myString); int sensors[] = int(split(myString, ',')); for (int sensorNum = 0; sensorNum < sensors.length; sensorNum++) { // print the sensor values print("Sensor " + sensorNum + ": " + sensors[sensorNum] + "\t"); } println(); if(sensors.length > 1) { // adjust the value of sensors[0] and set as freq float freq = map(sensors[0], 0, 4978, 1500, 60); // set the frequency to the new values sine.setFreq(freq); // adjust the value of sensors[1] and set as amp float amp = map(sensors[1], 0, 4978, -1, 1); // set the amplitude to the new values sine.setAmp(amp); } } sine.setPan(0); // set speaker balance to even } void stop() {
out.close(); minim.stop(); super.stop(); } A Fritzing picture of the circuit is attached. |
1-10 of 39