Go Down

Topic: Analog control of 15 outputs - Beginner question (Read 383 times) previous topic - next topic

otacon239

I'm setting up a project using the Arduino and I'm the very early stages of design. I was just wondering if someone could help me out with some basics.

What are some reading materials I could be pointed towards to help with a project that I need the following for. I plan on using the Arduino Pro Mini due to its light weight and small size for the project, which will be wearable. I need to, by the end of my project, have the ability to do the following things:

1. Get full analog control of 15 individual outputs (5 RGB LEDs)
2. Have 4-5 digital inputs
3. Create a system for simple syntax of this control (LED#, color, brightness)

If someone could just point me towards a website or book, that would be fine. I'm just not sure where to get started since many of the materials I've been finding don't have a lot of info on such a specific design for obvious reasons. Thanks a ton to anyone who helps. Also, I would like to refrain from using preexisting shields as I will be using the Pro Mini and I need this design to be compact and simple.

Grumpy_Mike

For that many outputs you need an external chip. A popular one is the TLC5940 google that for help with it.

mixania

#2
Mar 18, 2013, 05:01 pm Last Edit: Mar 18, 2013, 06:03 pm by mixania Reason: 1
As Grumpy_Mike you would certainly need some additional hardware to handle all of those outputs.That's a separate task to deal with.  :smiley-roll:

Setting up the digital input won't be a problem. Here is an example of setting up a digital input using a button and a 10K resistor:  
http://arduino.cc/en/tutorial/button :)

Or if you don't have a 10K resistor you could use the internal pull-up resistor right on the Arduino which would save up some wiring. Here is a video tutorial:
http://youtu.be/jJnD6LdGmUo

Also be aware that Arduino Mini has only 6 PWM outputs and you need 15 of them which means you would need some extension for that too. That's something hard for me to explain since I have no good knowledge in that.  :smiley-roll-sweat:

I could guide you through the  "system for simple syntax of this control" as I like it how you call it, very formal.  ;)

First of all, you could create your own function. Here is a link to it if you won't understand my explanation:
http://arduino.cc/en/Reference/FunctionDeclaration

So you want: (LED#, color, brightness). Lets create a function and call it "rgbControl" and let it control some of the attributes.
Note: I will separate the color section into three sections, R, G and B. I will remove the LED number in you proposal but you can add it any time

Code: [Select]

void  rgbControl(int r, int g, int b, float brightness){
 // let's say the RGB led has its RGB pins on number 1,2 and 3
 // Input the brightness in percentages
 analogWrite(1,(r*brightness/100)); // lets set its red value
 analogWrite(2,(g*brightness/100)); // lets set its green value
 analogWrite(3,(b*brightness/100)); // lets set its  blue value
}


Put this code before or after the loop() function (not in the function). And in the loop() itself you could write something like

This will give you a red at a 50% brightness:
Code: [Select]
rgbControl(256,0,0,50);

This will give you a green at a 80% brightness:
Code: [Select]
rgbControl(0,256,0,80);

This will give you a red at a 100% brightness:
Code: [Select]
rgbControl(0,0,256,100);


The final sketch may look something like:
Code: [Select]


void setup () {
}

void loop () {
 rgbControl(256,0,0,50); //This will give you a red at a 50% brightness:
 rgbControl(0,0,0,0);    //Set values to off
 rgbControl(0,256,0,80); //This will give you a green at a 80% brightness:
 rgbControl(0,0,0,0);    //Set values to off
 rgbControl(0,0,256,100); //This will give you a red at a 100% brightness:
 rgbControl(0,0,0,0);     //Set values to off
}
void  rgbControl(int r, int g, int b, float brightness){
 // let's say the RGB led has its RGB pins on number 1,2 and 3
 // Input the brightness in percentages
 analogWrite(1,(r*brightness/100)); // lets set its red value
 analogWrite(2,(g*brightness/100)); // lets set its green value
 analogWrite(3,(b*brightness/100)); // lets set its  blue value
}


I hope this will get you started. If you have questions just ask :)
Arduino Uno R3
Mac OSX Lion

Go Up