Nancy’s final project

I am sorry that I forgot to write the documentation until now. But for the convenience of those from next class who might also want to do music visualization in the future, I will introduce my project. I used a 8*8 LED matrix to show the visualization of a piece of music. How every column changes is related to the values of three variables, snare, hat and kick, which can be detected through the minimum library. There are sample codes in the folder named “examples”, which make the size of texts “Snare, Kick, Hat” changes according to the three variables. What is needed is to modify the codes and try to send the values of these three variables to the arduino through serial port. Then coding in the arduino to make the changes present on the LED screen.

Here is the video of how it works.

Here are the codes for the processing part:

import ddf.minim.*;
import ddf.minim.analysis.*;
import processing.serial.*;

Minim minim;
AudioPlayer song;
BeatDetect beat;
BeatListener bl;

Serial myPort;
int timer, timeOut;
float kickSend, hatSend, snareSend;

float kickSize, snareSize, hatSize;

boolean bStarted;

class BeatListener implements AudioListener
{
private BeatDetect beat;
private AudioPlayer source;

BeatListener(BeatDetect beat, AudioPlayer source)
{
this.source = source;
this.source.addListener(this);
this.beat = beat;
}

void samples(float[] samps)
{
beat.detect(source.mix);
}

void samples(float[] sampsL, float[] sampsR)
{
beat.detect(source.mix);
}
}

void setup()
{ timer = 0;
timeOut = 100;
size(512, 200, P3D);
frameRate(60);

minim = new Minim(this);

song = minim.loadFile(“Call Me Maybe.mp3”, 1024);
song.play();
// a beat detection object that is FREQ_ENERGY mode that
// expects buffers the length of song’s buffer size
// and samples captured at songs’s sample rate
beat = new BeatDetect(song.bufferSize(), song.sampleRate());
// set the sensitivity to 300 milliseconds
// After a beat has been detected, the algorithm will wait for 300 milliseconds
// before allowing another beat to be reported. You can use this to dampen the
// algorithm if it is giving too many false-positives. The default value is 10,
// which is essentially no damping. If you try to set the sensitivity to a negative value,
// an error will be reported and it will be set to 10 instead.
beat.setSensitivity(50);
myPort = new Serial(this, “COM3”, 9600);
kickSize = snareSize = hatSize = 16;
// make a new beat listener, so that we won’t miss any buffers for the analysis
bl = new BeatListener(beat, song);
textFont(createFont(“Helvetica”, 16));
textAlign(CENTER);
}

void draw()
{
background(0);
fill(255);
if ( beat.isKick() ) kickSize = 32;
if ( beat.isSnare() ) snareSize = 62;
if ( beat.isHat() ) hatSize = 72;
textSize(kickSize);
//text(“KICK”, width/4, height/2);
textSize(snareSize);
//text(“SNARE”, width/2, height/2);
textSize(hatSize);
//text(“HAT”, 3*width/4, height/2);
kickSize = constrain(kickSize * 0.95, 16, 32);
snareSize = constrain(snareSize * 0.95, 16, 32);
hatSize = constrain(hatSize * 0.95, 16, 32);
kickSend = map(kickSize, 16, 32, 0, 6);
snareSend = map(snareSize, 16, 32, 0, 6);
hatSend = map(hatSize, 16, 32, 0, 6);

println(“—“);
//println(kickSize);
println(kickSend);
myPort.write(int(200));
myPort.write(int(kickSend));
myPort.write(int(snareSend));
myPort.write(int(hatSend));

Here are the codes for the arduino part:

/*
Rainbowduino v3.0 Library examples:

Print Shapes on 2D plane (8×8 matrix)

*/

#include <Rainbowduino.h>
int incomingByte = 0;
byte serialArray[7];
int serialArrayPos = 0;
//int colorArray[6]={};
boolean readFlag = false;
//int incomingByte = 0;
//int previousByte = 0;
//int serialArrayPos = 0;

void setup()
{
Rb.init();
Serial.begin(9600);
}
unsigned char x,y,z;

void loop()
{
// read the incoming byte:
readFlag = false;
serialArrayPos = 0;
do {
if (Serial.available() > 0){
incomingByte = Serial.read();
if (incomingByte == 200) {
do {
if (Serial.available() > 0) {
incomingByte = Serial.read();
serialArray[serialArrayPos] = incomingByte;
serialArrayPos++;
}
}
while (serialArrayPos < 3);
readFlag = true;
}
//Serial.print(serialArrayPos + ‘:’);
//Serial.println(incomingByte);
}
}
while (readFlag == false);
Rb.blankDisplay();
for (int j = 0;j < 3; j += 1) {
//if ( serialArray[i]== 75) {
// Rb.blankDisplay();
//Rb.drawLine(0, 0, 0, serialArray[i-1], 0xE80C7A); // draw a red circle of radius 3 at (3,4). } else if (incomingByte == int(40) {
//Serial.println(previousByte-48);
//Rb.drawLine(1, 0, 1, serialArray[i-1]+1, 0xE8481E);
// delay(10);
// }

Rb.drawLine(j, 0, j, serialArray[j], random(0xFFEAAE));
Rb.drawLine(j+3, 0, j+3, serialArray[j]+1, random(0x55CCEE));
//Rb.drawLine(2, 0, 2, serialArray[2], random(0x55CCEE));
//Rb.drawLine(3, 0, 3, (serialArray[0]+serialArray[2])/2, random(0x55CCEE));
// Rb.drawLine(4, 0, 4, (serialArray[0]+serialArray[2])/2, random(0x55CCEE));
Rb.drawLine(6, 0, 6, (serialArray[0]+serialArray[1])/2, random(0x55CCEE));
Rb.drawLine(7, 0, 7, (serialArray[1]+serialArray[2])/2, random(0x55CCEE));

}
}

The most difficult part is to let the processing send the values detected in groups, which means a one group could only include the values of snare, hat and kick at the same time. The way to figure it out is to let the processing send one more value before the three values, which is 200 in these codes. Using an array and a boolean to let the arduino only receive the values after 200 at one time.

Thanks a lot to Matt, Vivian and Bruce who help me with the project and make me feel less stressful.

Final Project: Printbox

For this project, I used NFC (Near Field Communication) and a thermal printer to create a convenient solution for printing quickly from your mobile phone.

*In this stage of Printbox, you must store your data from an nfc device to a small nfc tag that the nfc reader attached to the Arduino can process. In the future, I would like to be able to figure out direct communication between the phone and Printbox. I initially had a lot of trouble getting the NFC reader and printer to talk to each other, but finally succeeded with help.

I loved making a presenting this project, and couldn’t be happier that it ended up actually working!

IMG_20140527_161800_146 IMG_20140527_162215_377

 

 

 

Code:

//NFC
#include “PN532_HSU.h”
#include “PN532.h”
#include “NfcAdapter.h”

PN532_HSU interface(Serial1);
NfcAdapter nfc = NfcAdapter(interface);

//Printer
#include “SoftwareSerial.h”
#include “Adafruit_Thermal.h”
//#include “adalogo.h”
//#include “adaqrcode.h”
#include <avr/pgmspace.h>

int printer_RX_Pin = 5; // This is the green wire
int printer_TX_Pin = 6; // This is the yellow wire

String payload;

Adafruit_Thermal printer(printer_RX_Pin, printer_TX_Pin);

void setup(void) {
Serial.begin(9600); //nfc
Serial.println(“NDEF Reader”);
nfc.begin();

//printer
pinMode(7, OUTPUT); digitalWrite(7, LOW); // To also work w/IoTP printer
printer.begin();

/* printer.justify(‘R’);
printer.feed(1);
printer.println(“Right justified”);
printer.justify(‘C’);
printer.feed(1);
printer.println(“Center justified”);
printer.justify(‘L’);
printer.println(“Left justified”);

printer.feed(1);

*/
//printer.sleep(); // Tell printer to sleep
//printer.setDefault(); // Restore printer to defaults

}

void loop(void) {
Serial.println(“\nScan a NFC tag\n”);

if (nfc.tagPresent())
{
NfcTag tag = nfc.read();
Serial.println(tag.getTagType());
Serial.print(“UID: “);Serial.println(tag.getUidString());

if (tag.hasNdefMessage()) // every tag won’t have a message
{

NdefMessage message = tag.getNdefMessage();
Serial.print(“\nThis NFC Tag contains an NDEF Message with “);
Serial.print(message.getRecordCount());
Serial.print(” NDEF Record”);
if (message.getRecordCount() != 1) {
Serial.print(“s”);
}
Serial.println(“.”);

// cycle through the records, printing some info from each
int recordCount = message.getRecordCount();
for (int i = 0; i < recordCount; i++)
{
Serial.print(“\nNDEF Record “);Serial.println(i+1);
NdefRecord record = message.getRecord(i);
// NdefRecord record = message[i]; // alternate syntax

Serial.print(” TNF: “);Serial.println(record.getTnf());
Serial.print(” Type: “);Serial.println(record.getType()); // will be “” for TNF_EMPTY

// The TNF and Type should be used to determine how your application processes the payload
// There’s no generic processing for the payload, it’s returned as a byte[]
int payloadLength = record.getPayloadLength();
byte payload[payloadLength];
record.getPayload(payload);

// Print the Hex and Printable Characters
Serial.print(” Payload (HEX): “);
PrintHexChar(payload, payloadLength);

// Force the data into a String
// Real code should use smarter processing
String payloadAsString = “”;
for (int c = 0; c < payloadLength; c++) {
payloadAsString += (char)payload[c][/c];
}
Serial.print(” Payload (as String): “);
Serial.println(payloadAsString);

String printString = payloadAsString.substring(3, payloadAsString.length());

// printer.wake(); // MUST call wake() before printing again, even if reset

printer.feed (1);
printer.underlineOn();
printer.boldOn();
printer.justify(‘C’);
printer.setSize(‘M’);
printer.println(“PrintBox Says:”);
printer.underlineOff();
printer.boldOff();

//printer.feed(1);
printer.setSize(‘S’);
printer.justify(‘L’);
//printer.feed(1);
printer.println(printString);

//printer.feed(1);
printer.setSize(‘S’);
printer.justify(‘C’);
printer.println(” *** \n Thanks for using PrintBox, the \n open-source NFC printer \n created by Sean Kelly in 2014.”);

printer.feed(3);

// printer.sleep(); // MUST call wake() before printing again, even if reset

// id is probably blank and will return “”
String uid = record.getId();
if (uid != “”) {
Serial.print(” ID: “);Serial.println(uid);
}
}
}
}
delay(3000);

}

Exercise 10: Audio in Processing

In this lab, I used processing to cover the Beatles’ hit single “Let it Be” released in 1970.

When the sketch is run, sine waves play the first chords of the song.

Code:

import ddf.minim.*;
import ddf.minim.ugens.*;

Minim minim;
AudioPlayer player;
AudioOutput out;
Oscil wave;
void setup (){
size (640,100);
minim = new Minim(this);
//player = minim.loadFile(“Pull Up Dat Booty copy.mp3″); //comment out
//player.play(); //comment out for no track

out = minim.getLineOut();

//wave = new Oscil (100,1, Waves.SAW);
//wave.patch(out);

out = minim.getLineOut();
out.setTempo(100);
out.pauseNotes();
out.playNote(0,2,”C4″);
out.playNote(0,2,”E4″);
out.playNote(0,2,”G4″);
out.resumeNotes();

delay(800);

out.playNote(0,2,”C4″);
out.playNote(0,2,”E4″);
out.playNote(0,2,”G4″);

delay(800);

out.playNote(0,2,”G3″);
out.playNote(0,2,”B3″);
out.playNote(0,2,”D3″);

delay(800);

out.playNote(0,2,”G3″);
out.playNote(0,2,”B3″);
out.playNote(0,2,”D3″);

delay(800);

out.playNote(0,2,”A3″);
out.playNote(0,2,”C3″);
out.playNote(0,2,”E3″);

delay(800);

out.playNote(0,2,”A3″);
out.playNote(0,2,”C3″);
out.playNote(0,2,”E3″);

delay(400);
out.playNote(0,2,”G3″);
out.playNote(0,2,”B3″);
out.playNote(0,2,”D3″);

delay(400);
out.playNote(0,2,”F3″);
out.playNote(0,2,”A3″);
out.playNote(0,2,”C3″);

delay(800);
out.playNote(0,2,”F3″);
out.playNote(0,2,”A3″);
out.playNote(0,2,”C3″); // end of first phrase

delay(800);
out.playNote(0,2,”C4″);
out.playNote(0,2,”E4″);
out.playNote(0,2,”G4″);
out.resumeNotes();

delay(800);

out.playNote(0,2,”C4″);
out.playNote(0,2,”E4″);
out.playNote(0,2,”G4″);

delay(800);

out.playNote(0,2,”G3″);
out.playNote(0,2,”B3″);
out.playNote(0,2,”D3″);

delay(800);

out.playNote(0,2,”G3″);
out.playNote(0,2,”B3″);
out.playNote(0,2,”D3″);

delay(800);

out.playNote(0,2,”A3″);
out.playNote(0,2,”C4″);
out.playNote(0,2,”E4″);

delay(800);

out.playNote(0,2,”A3″);
out.playNote(0,2,”C4″);
out.playNote(0,2,”E4″);

delay(400);
out.playNote(0,2,”G3″);
out.playNote(0,2,”B3″);
out.playNote(0,2,”D3″);

delay(400);

out.playNote(0,4,”F3″);
out.playNote(0,4,”A3″);
out.playNote(0,4,”C3″);
out.playNote(0,2,”E#4”);
// end of 2nd phrase

}

void draw() {

/* background(0);
stroke (255);
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);

*/
}
/* void mouseMoved() {
wave.frequency.setLastValue(map(mouseX, 0, width, 0, 1000));
wave. amplitude.setLastValue(map(mouseY,0,height,0,1));
*/

 

Exercise 9- Read data into Processing and visualize it

For this Lab, I used a photo of Bryan Cranston that was clearly taken circa 1995. bry

 

Running the sketch, pixels would disappear until the photo became black, and as you rolled your mouse over the image, an indicator would appear showing what color the mouse is on.

image-4

 

Code:

PImage bry;
int clickCounter;

void setup () {
bry = loadImage (“bry.png”);
bry.loadPixels();

size (bry.width, bry.height);
cursor (CROSS);
}

void draw () {
for (int i = 0; i < bry.width*bry.height; i++) {
if (floor(random(200)) == 0) {
bry.pixels [i] = color (0,0,0);

}
}
bry.updatePixels();

image(bry, 0, 0);
float bryR = red (bry.pixels[mouseY*bry.width+mouseX]);
float bryG = green (bry.pixels[mouseY*bry.width+mouseX]);
float bryB = blue (bry.pixels[mouseY*bry.width+mouseX]);

fill (bryR, bryG, bryB);
stroke (255);
ellipse (mouseX+20, mouseY+20, 50,50);
}

void mousePressed () {
tint(color(floor(random(256))),
(floor(random(256))),
(floor(random(256))));
clickCounter++;
PImage saveImg = createImage(width, height, RGB);
saveImg = bry.get();
saveImg.save(“image-“+clickCounter+”.jpg”);

}

Jacko Walz Lab #7: Sensors

For my 7th Lab, I tried taking some steps forward in my Final Project by getting started with a sensor. I’m using Vibration Sensors in my project in order for the user to be able to play by blowing into them. So, for starters, I had to figure out how to work the Arduino and the code that went along with it.

After finding some help online, I was able to get blows to register, but at a somewhat shaky level. Eventually, I specified the threshold to what I needed it to be, and began to have more success.

I later decided to change to a more precise sensor that registered lower readings for the blows. This ended up being much more successful because I didn’t particularly need how hard someone was blowing, but rather, if they were, or were not.

Screen Shot 2014-05-29 at 2.45.53 PM

 

This lab helped me take some big steps forward for my final project!

Jacko Walz Lab #6: 3D Printing

For my 6th lab, I wanted to 3D print something for my girlfriend, because how awesome of a present is that?! I found code for a heart that I saw Jack making online, so I tried that. The code worked fine, and the thing looked great, but it wasn’t rotating like it was supposed to.

But after a while of picking at it with a knife, it finally gave and began to work!image (4)

After that, I ran through tutorials on Tinkercad.com and started playing around with them. I eventually designed a key hook that I’m planning on using in my room next year! Needless to say, the 3D printers are extremely cool.image (5)

Jacko Walz Final Project

For my final project, I made a game that combined Flappy Bird, a contemporary and fun game, with Pong, a classic game that is thought to be the first video game ever. Originally, my idea was just to include the physics of Flappy Bird into Pong, but during my Presentation, someone suggested I incorporate the act of blowing to keep the bird in the air, and I thought it was a great idea!

So I first designed a game of Pong in processing, which proved to be easier than I thought it would be. The next step was implementing Flappy Bird style physics. Being the first time I actually attempted a complex physics system, this was pretty challenging, as designing physics is far from intuitive.

Eventually, I figured it out. After this most difficult part was done, I began the simple process of connecting Arduino and Processing. Then I started 3D printing and laser cutting the physical aspects of the project so the blowing would function properly.

After a series of printer malfunctions, I finally got the project working the day before the deadline!

During the show, I realized that my laser cut piece was a bit too small, so the users weren’t particularly excited to squeeze their faces together in playing. I then began to just allow people to use the Vibration Sensors as buttons, which actually worked better.

So although the project didn’t end up exactly as I wanted, I think it was far from a disappointment.

Screen Shot 2014-05-29 at 2.31.07 PM image (3) image (2) image (1) image

Jacko Walz Lab #10: Using Images

For my 10th lab exercise, I created a drag and play interface with a football! The football bounces on the ground and is moved to wherever the user clicks the mouse, automatically. I got the image from the internet and used PImage to incorporate it into the code. I also made it so the more the ball bounces, the lower each bounce is. When the mouse is clicked in a new location, it restarts the bounce Screen Shot 2014-05-29 at 2.15.25 PMScreen Shot 2014-05-29 at 2.19.06 PM

July’s lab 9

I found a data visualization example online using  Google spreadsheet manager, and I followed it to see how it works.

Here’s the code.
SimpleSpreadsheetManager sm;
String sUrl = “t6mq_WLV5c5uj6mUNSryBIA”;
String googleUser = “YOUR USERNAME”;
String googlePass = “YOUR PASSWORD”;

PFont label;

void setup() {

size(800,800);
background(0);
smooth();

label = createFont(“Helvetica”, 24);

int[] numbers = getNumbers();
colorGrid(numbers, 50, 50, 70);
};

void barGraph(int[] nums, float y) {
int[] counts = new int[100];
for (int i = 1; i < 100; i++) {
counts[i] = 0;
};
for (int i = 0; i < nums.length; i++) {
counts[nums[i]] ++;
};

//Draw the bar graph
for (int i = 0; i < counts.length; i++) {
colorMode(HSB);
fill(counts[i] * 30, 255, 255);
rect(i * 8, y, 8, -counts[i] * 10);
};
};

void colorGrid(int[] nums, float x, float y, float s) {
int[] counts = new int[100];
for (int i = 0; i < 100; i++) {
counts[i] = 0;
};
for (int i = 0; i < nums.length; i++) {
counts[nums[i]] ++;
};

pushMatrix();
translate(x,y);
for (int i = 0; i < counts.length; i++) {
colorMode(HSB);
fill(counts[i] * 30, 255, 255, counts[i] * 30);
textAlign(CENTER);
textFont(label);
textSize(s/2);
text(i, (i % 10) * s, floor(i/10) * s);
};
popMatrix();
};

void draw() {

};

And this is what it will look like.

grid1-250x250