From a7fe0f86d869518fbc9aeec0e802c31ae9ef3e40 Mon Sep 17 00:00:00 2001 From: saad Date: Wed, 4 Oct 2023 01:40:58 -0400 Subject: [PATCH] add files --- DMX_TEST/DMX_TEST.pde | 41 ++++++++++++ audio_reactive/audio_reactive.pde | 65 +++++++++++++++++++ .../audio_reactive_3light.pde | 53 +++++++++++++++ 3 files changed, 159 insertions(+) create mode 100644 DMX_TEST/DMX_TEST.pde create mode 100644 audio_reactive/audio_reactive.pde create mode 100644 audio_reactive_3light/audio_reactive_3light.pde diff --git a/DMX_TEST/DMX_TEST.pde b/DMX_TEST/DMX_TEST.pde new file mode 100644 index 0000000..6c6ab48 --- /dev/null +++ b/DMX_TEST/DMX_TEST.pde @@ -0,0 +1,41 @@ +import processing.serial.*; + +Serial arduino; + +void setup() { + size(700, 600); + println(Serial.list()[0]); + String portName = Serial.list()[0]; //change the 0 to a 1 or 2 etc. to match your port + arduino = new Serial(this, portName, 9600); +} + +void draw() { + if (mousePressed == true) + { + if (mouseX >= 0 && mouseX <= 200){ + arduino.write("1c255w"); + } else if (mouseX >= 200 && mouseX <= 400){ + arduino.write("2c255w"); + } + else if (mouseX >= 400 && mouseX <= 600){ + arduino.write("3c255w"); + } + else if (mouseX >= 600 && mouseX <= 700){ + arduino.write("1c255w"); + arduino.write("2c255w"); + arduino.write("3c255w"); + } + } else { + arduino.write("1c0w"); + arduino.write("2c0w"); + arduino.write("3c0w"); + } + fill(255, 0, 0); + rect(0, 0, 200, 600); + fill(0, 255, 0); + rect(200, 0, 200, 600); + fill(0, 0, 255); + rect(400, 0, 200, 600); + fill(255, 255, 255); + rect(600, 0, 100, 600); +} diff --git a/audio_reactive/audio_reactive.pde b/audio_reactive/audio_reactive.pde new file mode 100644 index 0000000..52d9124 --- /dev/null +++ b/audio_reactive/audio_reactive.pde @@ -0,0 +1,65 @@ +import processing.sound.*; +import processing.serial.*; + +int NUM_LIGHTS = 3; + +FFT fft; +AudioIn in; +int bands = 4; +float[] spectrum = new float[bands]; + +Serial arduino; + +void setup() { + size(600, 300); + background(255); + + frameRate(14); + // Create an Input stream which is routed into the Amplitude analyzer + fft = new FFT(this, bands); + in = new AudioIn(this, 0); + + // start the Audio Input + in.start(); + + // patch the AudioIn + fft.input(in); + + String portName = Serial.list()[0]; //change the 0 to a 1 or 2 etc. to match your port + arduino = new Serial(this, portName, 9600); +} + +void draw() { + background(255); + fft.analyze(spectrum); + + for (int i = 0; i < bands; i++) { + // The result of the FFT is normalized + // draw the line for frequency band i scaling it up by 5 to get more amplitude. + if (i == 0) { + fill(255, 0, 0); + int val = (int)map(spectrum[i], 0, 1, 0, 255); + for (int k = 0; k < NUM_LIGHTS; k++){ + int channel = 1 + (k * 3); + arduino.write(channel+"c" + val + "w"); + } + + } else if (i == 1) { + int val = (int)map(spectrum[i], 0, 1, 0, 255); + val = val*2; + fill(0, 255, 0); + for (int k = 0; k < NUM_LIGHTS; k++){ + int channel = 2 + (k * 3); + arduino.write(channel+"c" + val + "w"); + } + } else if (i == 2) { + int val = (int)map(spectrum[i], 0, 1, 0, 255); + fill(0, 0, 255); + for (int k = 0; k < NUM_LIGHTS; k++){ + int channel = 3 + (k * 3); + arduino.write(channel+"c" + val + "w"); + } + } + rect(i * 200, 0, 200, spectrum[i] * height); + } +} diff --git a/audio_reactive_3light/audio_reactive_3light.pde b/audio_reactive_3light/audio_reactive_3light.pde new file mode 100644 index 0000000..30f1ad9 --- /dev/null +++ b/audio_reactive_3light/audio_reactive_3light.pde @@ -0,0 +1,53 @@ +import processing.sound.*; +import processing.serial.*; + + +FFT fft; +AudioIn in; +int bands = 4; +float[] spectrum = new float[bands]; + +Serial arduino; + +void setup() { + size(600, 300); + background(255); + + frameRate(14); + // Create an Input stream which is routed into the Amplitude analyzer + fft = new FFT(this, bands); + in = new AudioIn(this, 0); + + // start the Audio Input + in.start(); + + // patch the AudioIn + fft.input(in); + + String portName = Serial.list()[0]; //change the 0 to a 1 or 2 etc. to match your port + arduino = new Serial(this, portName, 9600); +} + +void draw() { + background(255); + fft.analyze(spectrum); + + for (int i = 0; i < bands; i++) { + // The result of the FFT is normalized + // draw the line for frequency band i scaling it up by 5 to get more amplitude. + if (i == 0) { + fill(255, 0, 0); + int val = (int)map(spectrum[i], 0, 1, 0, 255); + arduino.write("1c" + val + "w"); + } else if (i == 1) { + int val = (int)map(spectrum[i], 0, 1, 0, 255); + fill(0, 255, 0); + arduino.write("5c" + val*2 + "w"); + } else if (i == 2) { + int val = (int)map(spectrum[i], 0, 1, 0, 255); + fill(0, 0, 255); + arduino.write("9c" + val*3 + "w"); + } + rect(i * 200, 0, 200, spectrum[i] * height); + } +}