Last active
December 6, 2024 23:38
-
-
Save jedgarpark/4f5ec1bde85090aebef054a662ef8779 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Conceptinetics.h> | |
#include <Adafruit_NeoPixel.h> | |
#define NUMSTRIPS 2 | |
#define STRIP1_PIN A0 | |
#define STRIP2_PIN A2 | |
#define STRIP1_NUMPIXELS 30 | |
#define STRIP2_NUMPIXELS 20 | |
Adafruit_NeoPixel strip1(STRIP1_NUMPIXELS, STRIP1_PIN, NEO_GRB + NEO_KHZ800); // set proper color order here, typical is 'GRB', the Adafruit 'heart', 'ball', 'sphere' strips are BGR | |
Adafruit_NeoPixel strip2(STRIP2_NUMPIXELS, STRIP2_PIN, NEO_BGR + NEO_KHZ800); | |
#define DMX_CHANNELS1 32 | |
// Configure a DMX receiving controller | |
DMX_Slave dmx_slave ( DMX_CHANNELS1 ); | |
const int ledPin = 13; | |
uint16_t channelValues[DMX_CHANNELS1]; // Array to store DMX values | |
void setup() { | |
// Enable DMX receiving interface and start receiving DMX data | |
dmx_slave.enable (); | |
dmx_slave.setStartAddress (1); | |
// Set led pin as output pin | |
pinMode ( ledPin, OUTPUT ); | |
digitalWrite(ledPin, HIGH); | |
strip1.begin(); | |
strip2.begin(); | |
//run through RGB to confirm NeoPixels are working and color order is correct | |
uint32_t startupColors[] = {0xff0000, 0x00ff00, 0x0000ff}; // Red, Green, Blue | |
const int numColors = sizeof(startupColors) / sizeof(startupColors[0]); // Get the number of colors in the array | |
for (int i = 0; i < numColors; i++) { | |
strip1.fill(startupColors[i]); // Set the color from the array | |
strip1.show(); | |
delay(800); // Wait for 500ms before moving to the next color | |
} | |
strip1.clear(); | |
strip1.show(); | |
for (int i = 0; i < numColors; i++) { | |
strip2.fill(startupColors[i]); // Set the color from the array | |
strip2.show(); | |
delay(800); // Wait for 500ms before moving to the next color | |
} | |
strip2.clear(); | |
strip2.show(); | |
} | |
void loop() | |
{ | |
// Fetch all DMX channel values into the array | |
for (int i = 0; i < DMX_CHANNELS1; i++) { | |
channelValues[i] = dmx_slave.getChannelValue(i + 1); // Get values starting from channel 1 | |
} | |
// Map DMX values for hue and pixel positions | |
uint16_t strip1_hue1 = map(channelValues[0], 0, 255, 0, 65535); | |
uint16_t strip1_hue2 = map(channelValues[4], 0, 255, 0, 65535); | |
uint16_t strip1_pix1 = map(channelValues[3], 0, 255, 0, STRIP1_NUMPIXELS - 1); | |
uint16_t strip1_pix2 = map(channelValues[7], 0, 255, 0, STRIP1_NUMPIXELS - 1); | |
uint16_t strip2_hue1 = map(channelValues[16], 0, 255, 0, 65535); | |
uint16_t strip2_hue2 = map(channelValues[20], 0, 255, 0, 65535); | |
uint16_t strip2_pix1 = map(channelValues[19], 0, 255, 0, STRIP2_NUMPIXELS - 1); | |
uint16_t strip2_pix2 = map(channelValues[23], 0, 255, 0, STRIP2_NUMPIXELS - 1); | |
strip1.fill(0x000000); | |
strip1.setPixelColor(strip1_pix1, strip1.ColorHSV(strip1_hue1, channelValues[1], channelValues[2])); | |
strip1.setPixelColor(strip1_pix2, strip1.ColorHSV(strip1_hue2, channelValues[5], channelValues[6])); | |
strip2.fill(0x000000); | |
strip2.setPixelColor(strip2_pix1, strip2.ColorHSV(strip2_hue1, channelValues[17], channelValues[18])); | |
strip2.setPixelColor(strip2_pix2, strip2.ColorHSV(strip2_hue2, channelValues[21], channelValues[22])); | |
// Interpolate between pixels | |
for (int i = strip1_pix1; i <= strip1_pix2; i++) { | |
// Calculate the fraction of the interpolation (0 to 1) | |
float fraction = float(i - strip1_pix1) / float(strip1_pix2 - strip1_pix1); | |
// Interpolate HSV components (Hue, Saturation, Value) | |
uint16_t interpolated_hue = int(lerp(strip1_hue1, strip1_hue2, fraction)) % 65536; // Wrap around Hue | |
uint16_t interpolated_saturation = lerp(channelValues[1], channelValues[5], fraction); | |
uint16_t interpolated_value = lerp(channelValues[2], channelValues[6], fraction); | |
// Set the interpolated color to the pixel | |
strip1.setPixelColor(i, strip1.ColorHSV(interpolated_hue, interpolated_saturation, interpolated_value)); | |
} | |
for (int i = strip2_pix1; i <= strip2_pix2; i++) { | |
// Calculate the fraction of the interpolation (0 to 1) | |
float fraction = float(i - strip2_pix1) / float(strip2_pix2 - strip2_pix1); | |
// Interpolate HSV components (Hue, Saturation, Value) | |
uint16_t interpolated_hue = int(lerp(strip2_hue1, strip2_hue2, fraction)) % 65536; // Wrap around Hue | |
uint16_t interpolated_saturation = lerp(channelValues[17], channelValues[21], fraction); | |
uint16_t interpolated_value = lerp(channelValues[18], channelValues[22], fraction); | |
// Set the interpolated color to the pixel | |
strip2.setPixelColor(i, strip2.ColorHSV(interpolated_hue, interpolated_saturation, interpolated_value)); | |
} | |
strip1.show(); | |
strip2.show(); | |
delay(100); | |
} | |
// Linear interpolation function | |
float lerp(float start, float end, float t) { | |
return start + (end - start) * t; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment