Arduino + Winamp charlieplexed 6X5
by Dave Johnson
Ardor from arduino.cc posted a question about simplifying his charlieplexed code, and I didn’t have a straight answer for him because I haven’t charlieplexed before. So in order to solve this I built myself a 6×5 led array using 6 wires. I pretty much copied Andrew Magill’s design on everything except I’m using an Arduino.
so my answer for simplifying the code was two arrays… one that would store the led location and one that would decide whether to turn it on or off. once i had that figured out then i just mixed in my code for processing the winamp data and that was it. the hardest part was trying to get a 950 micro second delay working.. on all my previous projects this wasn’t hard but for some reason this one put up a fight.
I’ll be working on a detailed tutorial later on this week.
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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | /* --- Arduino + Winamp charlieplexed --- Copyright 2011 - Dave Johnson --- Dave@SilverCG.com - www.SilverCG.com */ #include <Charlieplex.h> #define A 0 // index number of pins[] array #define B 1 #define C 2 #define D 3 #define E 4 #define F 5 #define NUMBER_OF_PINS 6 byte pins[] = {5,6,7,8,9,10}; // arduino pins Charlieplex plex = Charlieplex(pins,NUMBER_OF_PINS); long previousMillis = 0; long interval = 950; //micro second delay int j = 0; int i = 0; int data[10]; //array of all leds, int c[5][6][2] = { { {F, A}, {E, A}, {D, A}, {C, A}, {B, A}, {A, B} }, { {F, B}, {E, B}, {D, B}, {C, B}, {B, C}, {A, C} }, { {F, C}, {E, C}, {D, C}, {C, D}, {B, D}, {A, D} }, { {F, D}, {E, D}, {D, E}, {C, E}, {B, E}, {A, E} }, { {F, E}, {E, F}, {D, F}, {C, F}, {B, F}, {A, F} }, }; void setup() { Serial.begin(57600); } void loop() { int full[35]; int divide = 2; float total; if (Serial.available() > 10) { byte x = Serial.read(); if (int(x) == 255) { for (int h = 0; h <= 9; h++){ data[h] = int(Serial.read()); } } } // this is hard for my to explain and it's hard to understand for (int i = 0; i < 35; i++){ full[i] = 0; }// clears the full[] array int length = 1; // sets the length of leds in each column for (int i = 0; i < 6; i++){// for every column int maplvls[6]; int maplvlsM[6]; maplvls[i] = map(data[i+3], 0, 255, 0, 7);// map to 0-6 and 0 is all off if (maplvls[i] > length) { maplvlsM[i] = maplvls[i] - length; } for (int z = maplvlsM[i]; z < maplvls[i]; z++){ full[z + ((i * 5) - 1)] = 1; //smart math to decide where to put the 1 } } // this is the finshed array of 1's and 0's or on/off int list[5][6] = { { full[4], full[9], full[14], full[19], full[24], full[29]}, { full[3], full[8], full[13], full[18], full[23], full[28]}, { full[2], full[7], full[12], full[17], full[22], full[27]}, { full[1], full[6], full[11], full[16], full[21], full[26]}, { full[0], full[5], full[10], full[15], full[20], full[25]} }; //test code to check setup... // int list[5][6] = //{ // { 1, 1, 1, 1, 1,1}, // { 1, 1, 1, 1, 1, 1}, // { 1, 1, 1, 0, 1, 1}, // { 1, 1, 0, 0, 0, 1}, // { 1, 0, 0, 0, 0, 0} //}; if (j >= 6){ j=0; } charliePin LED0 = {c[0][j][0], c[0][j][1]}; charliePin LED1 = {c[1][j][0], c[1][j][1]}; charliePin LED2 = {c[2][j][0], c[2][j][1]}; charliePin LED3 = {c[3][j][0], c[3][j][1]}; charliePin LED4 = {c[4][j][0], c[4][j][1]}; unsigned long currentMillis = micros(); int count = 0; if (list[0][j] == 1){ //checks to see if it's on or off plex.charlieWrite(LED0,HIGH); } if (list[1][j] == 1){ plex.charlieWrite(LED1,HIGH); } if (list[2][j] == 1){ plex.charlieWrite(LED2,HIGH); } if (list[3][j] == 1){ plex.charlieWrite(LED3,HIGH); } if (list[4][j] == 1){ plex.charlieWrite(LED4,HIGH); } plex.clear(); if(currentMillis - previousMillis > interval) { previousMillis = currentMillis; j+=1; } } |
Arduino RGB LED + Winamp
by Dave Johnson
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; } } } } |
Arduino + Winamp vu meter
by Dave Johnson
This is one of the pieces of code that I’ve delayed posting for a long time. For those that wanted it I’m deeply sorry that it has taken me this long.
This is a Script that really only works is you have all the pieces.
So first you need the plugin for winamp that Maceger provided to me.
http://www.macetech.com/wa502_sdk.zip
also my version is available on my download page
** for this to work you need to download and open the project in visual studio and do a search for “COM” and change it to your COM port of your computer. Then compile the dll, and put it into the C:\Program Files\Winamp\Plugins folder ***
second you need softPWM (optional)
http://arduino.cc/forum/index.php/topic,19451.0.html
if you chose not to use it you will need to change SoftPWMSet to digitalWrite, and remove all SoftPWM code.
support topics on my project can be found at the fallowing links.
http://arduino.cc/forum/index.php/topic,40078.msg293360.html#msg293360
http://arduino.cc/forum/index.php/topic,27482.msg203610.html#msg203610
UPDATE:: source code.zip
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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | /*################################################# ### --- Winamp + arduio vu meter ---- ### ### --- Copyright 2010 - Dave Johnson --- ### ###--- Dave@SilverCG.com - www.SilverCG.com --- ### ###_____________________________________________### ### --- this code includes a vu meter based off ### ### data from winamp and converts it to 3 rows ### ### of multiplexed leds. ---- ### #################################################*/ #include <SoftPWM.h> #define DELAY 80 int colpins[] = {2,3,4,5,6,7,8,9,10}; int rowpins[] = {11,12,13}; int power = 1; //--------------------------------------------- long timer; const long muxInterval = 10; int mux = 0; int full[27]; float lvl; void setup() { Serial.begin(57600); // for (int pin=0; pin<9; pin++) { // pinMode( colpins[pin], OUTPUT ); // } for (int pin=0; pin<3; pin++) { pinMode( rowpins[pin], OUTPUT ); } timer = millis(); SoftPWMBegin(); for (int i = 0; i < 9; i++){ SoftPWMSet(colpins[i], 0); } } void loop(){ int divide = 5; //------------------------------------------------------------ float total; // for calculations below. <> int data[9]; // raw serial data <> if (Serial.available() >10) { byte i = Serial.read(); if (int(i) == 255) { for (int c = 0; c < 9; c++){ data[c] = int(Serial.read()); } } } // some math ------------- lvl = (data[0] + data[1] + data[2] + data[3] + data[4] + data[5] + data[6] + data[7] + data[8]) / 9; //lvl = (data[1] + data[2] + data[3]) / divide; //lvl2 = (data[0] + data[7] + data[8]) / divide; //lvl3 = (data[4] + data[5] + data[6]) / divide; // math end ----------------- // reset leds --------------- for (int i = 0; i < 27; i++){ full[i] = 0; } int length = 5; // sets how long the tail is, so as the meter goes up there is 9 or less leds on at a times... // feel free to change this to what you like. // ------------------------------- int mapvalue2; int mapvalue = map(lvl, 0, 255, 0, 27); if (mapvalue >= length){ mapvalue2 = mapvalue - length + 1; } if (mapvalue < length) { mapvalue2 = 0; } for (int x = mapvalue2; x <= mapvalue; x++){ full[x] = 1; } // set leds end-------------- // patterns feel free to change these to what ever you want the posiblities are endless. 0 - 26 is equel to 27 leds.. // int meterlist[9]= {full[0], full[1], full[2], full[13], full[14], full[15], full[16], full[17], full[26]}; // int meterlist2[9] = {full[5], full[4], full[3], full[12], full[11], full[20], full[19], full[18], full[25]}; // int meterlist3[9] = {full[6], full[7], full[8], full[9], full[10], full[21], full[22], full[23], full[24]}; // //int meterlist[9]= {full[0], full[1], full[2], full[3], full[4], full[5], full[6], full[7], full[8]}; //int meterlist2[9] = {full[17], full[16], full[15], full[14], full[13], full[12], full[11], full[10], full[9]}; //int meterlist3[9] = {full[18], full[19], full[20], full[21], full[22], full[23], full[24], full[25], full[26]}; int meterlist[9]= {full[2], full[3], full[8], full[9], full[14], full[15], full[20], full[21], full[26]}; int meterlist2[9] = {full[1], full[4], full[7], full[10], full[13], full[16], full[19], full[22], full[25]}; int meterlist3[9] = {full[0], full[5], full[6], full[11], full[12], full[17], full[18], full[23], full[24]}; //int meterlist[9]= {full[0], full[6], full[12], full[18], full[5], full[11], full[17], full[23], full[26]}; //int meterlist2[9] = {full[1], full[7], full[13], full[19], full[4], full[10], full[16], full[22], full[26]}; //int meterlist3[9] = {full[2], full[8], full[14], full[20], full[3], full[9], full[15], full[21], full[26]}; //map to 9 //int meterlist[9]= {full[0], full[1], full[2], full[3], full[4], full[5], full[6], full[7], full[8]}; //int meterlist2[9]= {full[0], full[1], full[2], full[3], full[4], full[5], full[6], full[7], full[8]}; //int meterlist3[9]= {full[0], full[1], full[2], full[3], full[4], full[5], full[6], full[7], full[8]}; //int meterlist[9]= {full[26], full[16], full[14], full[4], full[2], full[8], full[10], full[20], full[22]}; //int meterlist2[9] = {full[24], full[18], full[12], full[6], full[0], full[6], full[12], full[18], full[24]}; //int meterlist3[9] = {full[22], full[20], full[10], full[8], full[2], full[4], full[14], full[16], full[26]}; //multiplex drawing. if (millis() - timer < muxInterval) { timer = millis(); mux++; if (mux > 2){ mux = 0; } for (int i = 0; i <=8; i++){ SoftPWMSet(colpins[i], 0); } digitalWrite(rowpins[0], LOW); digitalWrite(rowpins[1], LOW); digitalWrite(rowpins[2], LOW); if (mux == 0) { for (int i = 8; i >= 0; i--) { if (meterlist[i] == 1){ SoftPWMSet(colpins[i], power, true); digitalWrite(rowpins[0], HIGH); } } } if (mux == 1) { for (int i = 8; i >= 0; i--) { if (meterlist2[i] == 1){ SoftPWMSet(colpins[i], power, true); digitalWrite(rowpins[1], HIGH); } } } if (mux == 2) { for (int i = 8; i >= 0; i--) { if (meterlist3[i] == 1){ SoftPWMSet(colpins[i], power, true); digitalWrite(rowpins[2], HIGH); } } } } } |