creepy keyboard daft punk cat

Posted on Saturday, November 5th, 2011 at 9:15 am

CODE.
arduino:

// Sweep
// by BARRAGAN
// This example code is in the public domain.

#include

Servo myservo; // create servo object to control a servo
Servo myservo2;
int val;

void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
myservo2.attach(8); // attaches the servo on pin 9 to the servo object
Serial.begin (9600);
}

void loop() {

if (Serial.available()) {
val = Serial.read();

if (val == ‘Q’) {
myservo2.write(80);
}
if (val == ‘W’) {
myservo2.write(0);
}
if (val == ‘E’) {
myservo2.write(160);

}

if (val == ‘R’) {
myservo2.write(80);
myservo.write(86);

}

if (val == ‘A’) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(0); // tell servo to go to position in variable ‘pos’
delay(15); // waits 15ms for the servo to reach the position
}
if (val == ‘S’) { // goes from 180 degrees to 0 degrees

myservo.write(12); // tell servo to go to position in variable ‘pos’
delay(15); // waits 15ms for the servo to reach the position
}
if (val == ‘D’) {
myservo.write(24);

}
if (val == ‘F’) {
myservo.write(36);

}
if (val == ‘G’) {
myservo.write(48);

}
if (val == ‘H’) {
myservo.write(62);

}
if (val == ‘J’) {
myservo.write(74);

}
if (val == ‘K’) {
myservo.write(86);

}
if (val == ‘L’) {
myservo.write(98);

}
if (val == ‘Z’) {
myservo.write(110);

}
if (val == ‘X’) {
myservo.write(122);

}
if (val == ‘C’) {
myservo.write(134);

}
if (val == ‘V’) {
myservo.write(145);

}
if (val == ‘B’) {
myservo.write(156);

}
if (val == ‘N’) {
myservo.write(168);

}
if (val == ‘M’) {
myservo.write(180);

}
}
}

processing:

import ddf.minim.*;
import processing.serial.*;
PFont label;

import fullscreen.*;
FullScreen fs;
Minim minim;
boolean down = false;
int totalSounds = 16; // music files

AudioPlayer[] sound = new AudioPlayer[totalSounds];
int width_key = 48;

char Letras[] = {‘m’,'n’,'b’,'v’,'c’,'x’,'z’,'l’,'k’,'j’,'h’,'g’,'f’,'d’,'s’,'a’};

Keys[] lines = new Keys [totalSounds];

Serial port;

void setup() {
size(900, 400, P2D);
background(0);
smooth(); //anti-aliased
fs = new FullScreen(this);
fs.enter();
minim = new Minim(this);

println(Serial.list()); // List COM-ports

//select second com-port from the list
port = new Serial(this, Serial.list()[0], 9600);

float separation = width / (totalSounds + 2);
for (int i=0 ; i < lines.length; i++) {

float lnd = separation*i;
float xi = 0;
float xf = separation*(totalSounds - i) + 20;
float wide = 2;
float tone = 15 * i;
String name = "s_"+ i + ".wav";
AudioPlayer soundkey = minim.loadFile(name);
char letra = Letras[i];

lines[i] = new Keys(lnd, xi, xf, wide, tone, soundkey, letra);
port.write('R');
lines[i].displayfonts();

}
}

void keyReleased() {
down=false;
}

void draw() {

for (int i=0 ; i < lines.length; i++) {

lines[i].drawKeys();

if (mousePressed == true) {
print("mouse");
lines[i].playSound();

}
}
moveServo();
}

void stop() {

for (int i=1 ; i < sound.length; i++) {
sound[i].close();
}

minim.stop();

super.stop();
}

void moveServo() {

if (keyPressed && !down) {
down=true;
if (key == 'a') {
lines[0].soundkey.play(0);
manouno();
port.write('A');

}
if (key == 's') {
lines[1].soundkey.play(0);
manouno();
port.write('S');
}
if (key == 'd') {
lines[2].soundkey.play(0);
manouno();
port.write('D');
}
if (key == 'f') {
lines[3].soundkey.play(0);
manouno();
port.write('F');
}
if (key == 'g') {
lines[4].soundkey.play(0);
manouno();
port.write('G');
}
if (key == 'h') {
lines[5].soundkey.play(0);
manouno();
port.write('H');
}
if (key == 'j') {
lines[6].soundkey.play(0);
manouno();
port.write('J');
}
if (key == 'k') {
lines[7].soundkey.play(0);
manouno();
port.write('K');
}
if (key == 'l') {
lines[8].soundkey.play(0);
manodos();
port.write('L');
}
if (key == 'z') {
lines[9].soundkey.play(0);
manodos();
port.write('Z');
}
if (key == 'x') {
lines[10].soundkey.play(0);
manodos();
port.write('X');
}
if (key == 'c') {
lines[11].soundkey.play(0);
manodos();
port.write('C');
}
if (key == 'v') {
lines[12].soundkey.play(0);
manodos();
port.write('V');
}
if (key == 'b') {
lines[13].soundkey.play(0);
manodos();
port.write('B');
}
if (key == 'n') {
lines[14].soundkey.play(0);
manodos();
port.write('N');
}
if (key == 'm') {
lines[15].soundkey.play(0);
manodos();
port.write('M');
}
}
}

void manouno() {
port.write('E');
delay(250);
port.write('Q');
}

void manodos() {
port.write('W');
delay(250);
port.write('Q');
}

class_line:

class Keys {
float lnd, xi, xf, wide, tone;
AudioPlayer soundkey;
char letra;

Keys(float lnd_,float xi_, float xf_, float wide_, float tone_, AudioPlayer soundkey_, char letra_) {
lnd = lnd_;
xi = xi_;
xf = xf_;
wide = wide_;
tone = tone_;
soundkey = soundkey_;
letra = letra_;
}

void drawKeys() {

float a = height * (width – 1.5 * width / (totalSounds + 2))/(height – width_key) – lnd;
wide = wide + (width_key – wide)*0.1;
xi = xf;
stroke(255, 255 – tone, tone * 0.25);
strokeWeight(wide);
line (xi,0,xi,height*0.7);

}

void displayfonts() {
label = createFont(“HelveticaNeue-Thin.otf”, 30);
textFont(label);
text(letra, xf-5, height*0.78);

}

void playSound() {

if (( xi-wide*0.5 < mouseX) && (mouseX < xi+wide*0.5)) {
soundkey.play();
} else {

soundkey.rewind();
}

}

}

Comments are closed.

WordPress Themes