Task 1:
I managed to connect the cable, which took me about 1 min. FastLed has already been downloaded before the recitation. From the material, I learnt to give supply for the larger pixel boards to glow the same way.
Task 2:
I lit up accordingly, the second light in purple. To be seen in the link.
On copying the code, I produced the scene below.
Task 3:
I tried to let all the pixels’ colors change with the sound but I can’t. And found out that it was the problem with the “constrain” function. On changing “constrain” to “map” . “map” was very useful a function that by ratio, it could turn a variable from one range to another correspondingly while “constrain” only limited a variable within the maximum and minimum. This is the situation before the change.
This is after.
It is such an ambiguity that I wanted it to be all purple and only bring changes on the saturability of purple.
/* This is a code example for Processing, to be used on Recitation 7 You need to have installed the SerialRecord library. Interaction Lab IMA NYU Shanghai 2022 Fall */ import processing.sound.*; import processing.serial.*; import osteele.processing.SerialRecord.*; SoundFile sample; FFT fft; int bands =256; float smoothingFactor = 0.2; Serial serialPort; SerialRecord serialRecord; float[] sum = new float[bands]; int scale = 8; float barWidth; int W; //width of the tiles int NUM = 255; //amount of pixels int[] r = new int[NUM]; //red of each tile int[] g = new int[0]; //green of each tile int[] b = new int[NUM]; //blue of each tile void setup() { size(1024, 768); background(255); barWidth = 10*width/float(bands); sample = new SoundFile(this, "Post Malone - A Thousand Bad Times.mp3"); // You can use this syntax and change COM3 for your serial port // printArray(Serial.list()); // serialPort = new Serial(this, "COM3", 9600); // in MacOS it looks like "/dev/cu.usbmodem1101" //or you can try to use this instead: fft = new FFT(this, bands); fft.input(sample); String serialPortName = SerialUtils.findArduinoPort(); serialPort = new Serial(this, serialPortName, 9600); serialRecord = new SerialRecord(this, serialPort, 4); serialRecord.logToCanvas(false); rectMode(CENTER); } void draw() { background(125, 255, 125); fill(255, 0, 150); noStroke(); fft.analyze(); //int n = floor(constrain(mouseX/W , 0, NUM-1)); //r[n] = floor(255); //g[n] = floor(random(255)); //b[n] = floor(255); for (int i = 0; i < 32; i++) { // Smooth the FFT spectrum data by smoothing factor sum[i] += (fft.spectrum[i] - sum[i]) * smoothingFactor; // Draw the rectangles, adjust their height using the scale factor rect(i*barWidth, height, barWidth, -sum[i]*height*scale); r[i] = floor(255); g[i] = floor(random(255)); b[i] = floor(255); serialRecord.values[0] = i; // which pixel we change (0-59) serialRecord.values[1] = r[i]; // how much red (0-255) serialRecord.values[2] = g[i]; // how much green (0-255) serialRecord.values[3] = b[i]; // how much blue (0-255) serialRecord.send(); // send it! } } void mousePressed(){//点击鼠标 if(sample.isPlaying()){//如果声音在播放 sample.pause();//暂停 }else{//否则 sample.loop();//播放声音 //play()函数只播放声音一次 } }
But errors on behalf of the drive appeared. It said so:
SLF4J: Failed to load class “org.slf4j.impl.StaticLoggerBinder”.
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
RuntimeException: Error opening serial port /dev/cu.usbmodem11301: Port busy