Task #1: Test the NeoPixel
Task #2: Use your computer to light up NeoPixels
Task #3: Add Music!
import processing.sound.*; SoundFile sample; Amplitude analysis; import processing.serial.*; import osteele.processing.SerialRecord.*; Serial serialPort; SerialRecord serialRecord; int W; //width of the tiles int NUM = 60; //amount of pixels int[] r = new int[NUM]; //red of each tile int[] g = new int[NUM]; //red of each tile int[] b = new int[NUM]; //red of each tile int v; //volume shown on the neopixel void setup() { size(640, 480); W = width/NUM; // load and play a sound file in a loop sample = new SoundFile(this, "KillerQueen.wav"); sample.loop(); analysis = new Amplitude(this); analysis.input(sample); String serialPortName = SerialUtils.findArduinoPort(); serialPort = new Serial(this, serialPortName, 9600); serialRecord = new SerialRecord(this, serialPort, 5); //serialRecord.logToCanvas(false); rectMode(CENTER); } void draw() { //println(analysis.analyze()); background(255); noStroke(); float volume = analysis.analyze(); float diameter = map(volume, 0, 1, 0, width); fill(200, 50, floor(map(volume, 0, 0.5, 100, 255)), diameter); circle(width/2, height/2, diameter); v = floor(map(volume, 0, 1, 0, 60)); //the highest to light up for (int i=0; i<NUM; i ++) { //b[i] = floor(map(volume, 0, 0.5, 100, 255)); rect(floor(map(volume, 0, 0.8, 0, i * W + W/2)), random(0, 120), 6, 6); rect(floor(map(volume, 0, 1.0, 0, i * W + W/2)), random(120, 200), 7, 7); rect(floor(map(volume, 0, 1.2, 0, i * W + W/2)), random(200, 280), 9, 9); rect(floor(map(volume, 0, 1.0, 0, i * W + W/2)), random(280, 360), 7, 7); rect(floor(map(volume, 0, 0.8, 0, i * W + W/2)), random(360, 420), 6, 6); } if (frameCount % 100 == 0) { for (int i=0; i<NUM; i ++) { serialRecord.values[0] = i; // which pixel we change (0-59) serialRecord.values[1] = 80; // how much red (0-255) serialRecord.values[2] = 10; // how much green (0-255) serialRecord.values[3] = floor(map(volume, 0, 0.5, 100, 255)); serialRecord.send(); } } }
In this step I tried to change the Processing sketch and combine the rectangles in task 2 with the circle in task 3, but both animate with the volume. At first, I put the “serialRecord.send(); ” part inside the for loop, which might caused the sketch to run too slow and freeze from time to time. I also tried to let the LEDs light up following the beat but just failed to do that in the given time.
Music Reference:
Queen. “Killer Queen”. Spotify. https://open.spotify.com/track/4cIPLtg1avt2Jm3ne9S1zy?si=dd5359137a904be8.