Thursday, February 17, 2011

6 channel serial LED Dimmer w/ Arduino

While continuing research for senior project we came across the LanBox DMX controller. It essentially takes a hex string and converts it to DMX. Since the LanBox is expensive and we only have one, I wanted to make something that could function similarly for prototyping applications.

What I came up with was using all 6 PWM pins on the Arduino and assigning them intensities through a serial string beginning with "A"

Since allowable intensities varied between 0 and 255 I had the code break down the serial string into chunks of 3 characters. I dont know a whole ton about hex, but it would have been ideal.

So if you send the string "A255000255000122200"
channel intensities would be
  1. 255
  2. 000
  3. 255
  4. 000
  5. 122
  6. 200

The idea is that a whole string of all the instrument (LED) values would be sent in some sort of loop to control dimming operations so that minimal to no code would have to reside on the dmx device improving reliability of the system.

In the meantime, this is the code that I have come up with ideally I would like to be able to send information only on certain channels with some sort of identifier.

The exact code that is currently in use can be found after the break




/*
 this is a chunk of stuff to fade 3 leds from serial read
 
 */

//Callout LED pins
int ledA = 3;
int ledD = 5;
int ledC = 6;
int ledE = 9;
int ledF = 10;
int ledG = 11;

double A_lvl =64;
double D_lvl =64;
double C_lvl =64;
double E_lvl =64;
double F_lvl =64;
double G_lvl =64;
char kind_of_data;

void setup() {
  Serial.begin(115200); 
  analogWrite(ledA, A_lvl);         
  analogWrite(ledD, D_lvl);   
  analogWrite(ledC, C_lvl);
  analogWrite(ledE, E_lvl);         
  analogWrite(ledF, F_lvl);   
  analogWrite(ledG, G_lvl);
}

void loop()  { 
  while(Serial.available() > 0)
  {
    kind_of_data = Serial.read();
    if (kind_of_data == 'A' ) {

      delay(1);
      double A100 = Serial.read()- '0';
      delay(1);
      double A10 = Serial.read()- '0';
      delay(1);
      double A1 = Serial.read()- '0';
      A_lvl=A1+10*A10+A100*100;

      delay(1);
      double D100 = Serial.read()- '0';
      delay(1);
      double D10 = Serial.read()- '0';
      delay(1);
      double D1 = Serial.read()- '0';
      D_lvl=D1+10*D10+D100*100;

      delay(1);
      double C100 = Serial.read()- '0';
      delay(1);
      double C10 = Serial.read()- '0';
      delay(1);
      double C1 = Serial.read()- '0';
      C_lvl=C1+10*C10+C100*100;  

      delay(1);
      double E100 = Serial.read()- '0';
      delay(1);
      double E10 = Serial.read()- '0';
      delay(1);
      double E1 = Serial.read()- '0';
      E_lvl=E1+10*E10+E100*100;

      delay(1);
      double F100 = Serial.read()- '0';
      delay(1);
      double F10 = Serial.read()- '0';
      delay(1);
      double F1 = Serial.read()- '0';
      F_lvl=F1+10*F10+F100*100;

      delay(1);
      double G100 = Serial.read()- '0';
      delay(1);
      double G10 = Serial.read()- '0';
      delay(1);
      double G1 = Serial.read()- '0';
      G_lvl=G1+10*G10+G100*100;  

      analogWrite(ledA, int(A_lvl));         
      analogWrite(ledD, int(D_lvl));   
      analogWrite(ledC, int(C_lvl));
      analogWrite(ledE, int(E_lvl));         
      analogWrite(ledF, int(F_lvl));   
      analogWrite(ledG, int(G_lvl));

      Serial.print("A: ");
      Serial.println(A_lvl);
      Serial.print("D: ");
      Serial.println(D_lvl);
      Serial.print("C: ");
      Serial.println(C_lvl);
      Serial.print("E: ");
      Serial.println(E_lvl);
      Serial.print("F: ");
      Serial.println(F_lvl);
      Serial.print("G: ");
      Serial.println(G_lvl); 
    }
  }
}

1 comment:

  1. Hi, My name is Paul and I am the admin of a site called HackHut. You obviously have a lot of skill, and I just wanted to let you know about HackHut because it seems like a perfect fit for you. We are a hosting service somewhat like wordpress, blogspot, or Instructables accept run by and geared toward the hacker/DIYer. We offer, or are working on features that people like you want and can use. I hope you check us out and feel free to contact me there if you have any requests for features or questions about the site.

    ReplyDelete