Loading
Made a simple sound visualizer! It reacts primarily to bass. #Processing #Arduino #ChanceTheRapper
I used a sound impact sensor and a potentiometer to manipulate the processing sketch. Here is the code:
Arduino code is bellow:
int potData = A0;
int sound = 2;
int button = 4;
void setup() {
Serial.begin(57600); //higher baud rate for transfering longer strings of info
pinMode(potData, INPUT);
}
void loop() {
int potVal1 = analogRead(potData);
int soundVal2 = digitalRead(sound);
int buttonVal3 = digitalRead(button);
//concatenation happens bellow
//data format potVal1, soundVal2, buttonVal3 – this will package multiple bits of data
Serial.print(potVal1);
Serial.print(“|”); //adds a character that lets you separate different bits of data.
Serial.print(soundVal2);
Serial.print(“|”);
Serial.println(buttonVal3); //Ends the batch of data
delay(400);
}
Processing code is bellow:
import processing.serial.*;
Serial myPort; // Create object from Serial class
int val; // Data received from the serial port
void setup()
{
size(200, 200);
// 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()[0];
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
}
}