Yesterday I saw this posted by majordecibel on the arduino.cc forum. The main difference between mine and his is that i have no hardware. I’m using the same setup as this post except I created a new mod in the SVIS.dll.
the color is on a fade loop, and the brightness is determined by the music. pretty basic code, basic enough that I was able to build it in a few hours. when the delay is below 50ms the color transitions are rough. Also in my code I have it mapped to a min value of 80. this is so that when I have the Arduino unit behind my monitor it doesn’t bug the hell out of me.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | int blue = 3; int green = 5; int red = 6; int pwr = 11; long timer; const long muxInterval = 20; int mux = 0; int color[3] = {0,255,255}; int data[10]; float percent; void setup() { Serial.begin(57600); pinMode(blue, OUTPUT); pinMode(green, OUTPUT); pinMode(red, OUTPUT); pinMode(pwr, OUTPUT); timer = millis(); } void loop(){ if (Serial.available() > 10) { byte i = Serial.read(); if (int(i) == 255) { for (int c = 0; c <= 9; c++){ data[c] = int(Serial.read()); } } int total = ((data[2] + data[3]) / 2); total = map(total,0,255,80,255); //total = 200; percent = total / 255.00; int redTotal = ((color[2]*percent)); int greenTotal = ((color[1]*percent)); int blueTotal = ((color[0]*percent)); analogWrite(pwr, total); analogWrite(red, color[2]); analogWrite(green, color[1]); analogWrite(blue, color[0]); if (millis() - timer > muxInterval) { timer = millis(); mux++; if (mux > 1530){ mux = 1; } if (mux >= 1 && mux <= 255) { color[2] -= 1; } if (mux >= 256 && mux <= 510) { color[0] += 1; } if (mux >= 511 && mux <= 765) { color[1] -= 1; } if (mux >= 766 && mux <= 1020) { color[2] += 1; } if (mux >= 1021 && mux <= 1275) { color[0] -= 1; } if (mux >= 1276 && mux <= 1530) { color[1] += 1; } } } } |