Potentiometer Controlling LED Graph and Servo

I wouldn't go down this:

 for (int ledNr=0; ledNr<=36; ledNr++)
  {
    ledPin[ledNr] = ledPinNr-- ;
  }

route.

The LEDs as you have them numbered are consecutive anyway, so this approach is pointless - the whole thing could be done without arithmetically, without an array.

However, imagine you've (accidentally) soldered a couple of LEDs out of sequence, or there's a break in the sequence because you needed a pin for PWM or serial or something.
Arithmetic doesn't work anymore, so a "const byte" array is the way to do it.

You forgot to assign values to the LED[] array, so its no way of knowing what these values are (and what pins you set as OUTPUT).

#include <Servo.h>

int val1;
int val2;

int potPin = 0;

Servo servoPin;

int LED[35];

void setup()
{
 servoPin.attach(13);

 pinMode([glow]LED[0][/glow], OUTPUT);
 pinMode([glow]LED[1][/glow], OUTPUT);
 pinMode([glow]LED[2][/glow], OUTPUT);
.
.
.
etc

To use my former example slightly modified

int LED[35];  // 0 - 35, 36 LEDs. important to know what you use this value for! Here: output pin nr. A better name imho is LEDpin.
// Also distinguish the array's element's values, from the array index value (0 - 35 here)


void setup()
{
  // Assign output pin nr. to LED nr.
  int ledPinNr = 54; // start output pin nr.
  for (int ledNr=0; ledNr<36; ledNr++)
  {
    LED[ledNr] = ledPinNr-- ;
  }

  // Make all LED pins outputs
  for (int i = 0; i<36; i++)
  {
    pinMode(LED[i],OUTPUT);
  }
}

This should make an array 0-36, filled with the values 54-19, and also set the pin mode to output.

Ah, Groove is completely correct. I knew I was missing something really basic.. The array route for this particular case is pointless (sorry!). But for another day, if you use output pins not in sequence, for example, it would be.
And arrays are useful to know anyway.

const byte LED[[glow]36[/glow]] = {54, 53, 52, //etc };

in noob language please?

edit: you beat me by like 3 seconds

alrigth, so i changed it to a constant byte... now how do i tackle the pinMode situation???

for (int i = 0; i < sizeof(LED) / sizeof(LED[0]); ++i) {
  pinMode (LED[i], OUTPUT);
}

well, i have no clue how it works, but it works!!!

last but ont least the void loop...

current code:

#include <Servo.h> 

int val1;
int val2;

int potPin = 0; 

Servo servoPin;

const byte LED[36] = {54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19};

void setup()
{
 servoPin.attach(13); 
 
 for (int i = 0; i < sizeof(LED) / sizeof(LED[0]); ++i) {
  pinMode (LED[i], OUTPUT);
 } 
}

void loop()
{
 val1 = analogRead(potPin);
 val2 = analogRead(potPin);
 val1 = map(val1, 0, 1023, 0, 180);
 val2 = map(val2, 0, 1023, 0, 36);
 
 servoPin.write(val1);
 
  if (val2 >= 1){               
  digitalWrite(LED[0], HIGH);
 }
 else{
  digitalWrite(LED[0], LOW);
 }
 
 if (val2 >= 2){               
  digitalWrite(LED[1], HIGH);
 }
 else{
  digitalWrite(LED[1], LOW);
 }
 
  if (val2 >= 3){               
  digitalWrite(LED[2], HIGH);
 }
 else{
  digitalWrite(LED[2], LOW);
 }
 
  if (val2 >= 4){               
  digitalWrite(LED[3], HIGH);
 }
 else{
  digitalWrite(LED[3], LOW);
 }
 
  if (val2 >= 5){               
  digitalWrite(LED[4], HIGH);
 }
 else{
  digitalWrite(LED[4], LOW);
 }
 
  if (val2 >= 6){               
  digitalWrite(LED[5], HIGH);
 }
 else{
  digitalWrite(LED[5], LOW);
 }

 if (val2 >= 7){               
  digitalWrite(LED[6], HIGH);
 }
 else{
  digitalWrite(LED[6], LOW);
 }

 if (val2 >= 8){               
  digitalWrite(LED[7], HIGH);
 }
 else{
  digitalWrite(LED[7], LOW);
 }
 
 if (val2 >= 9){               
  digitalWrite(LED[8], HIGH);
 }
 else{
  digitalWrite(LED[8], LOW);
 }
 
 if (val2 >= 10){               
  digitalWrite(LED[9], HIGH);
 }
 else{
  digitalWrite(LED[9], LOW);
 } 
 
 if (val2 >= 11){               
  digitalWrite(LED[10], HIGH);
 }
 else{
  digitalWrite(LED[10], LOW);
 } 
 
 if (val2 >= 12){               
  digitalWrite(LED[11], HIGH);
 }
 else{
  digitalWrite(LED[11], LOW);
 } 
 
 if (val2 >= 1){               
  digitalWrite(LED[12], HIGH);
 }
 else{
  digitalWrite(LED[12], LOW);
 } 
 
 if (val2 >= 14){               
  digitalWrite(LED[13], HIGH);
 }
 else{
  digitalWrite(LED[13], LOW);
 } 
 
 if (val2 >= 15){               
  digitalWrite(LED[14], HIGH);
 }
 else{
  digitalWrite(LED[14], LOW);
 } 
 
 if (val2 >= 16){               
  digitalWrite(LED[15], HIGH);
 }
 else{
  digitalWrite(LED[15], LOW);
 }
 
 if (val2 >= 17){               
  digitalWrite(LED[16], HIGH);
 }
 else{
  digitalWrite(LED[16], LOW);
 } 
 if (val2 >= 18){               
  digitalWrite(LED[17], HIGH);
 }
 else{
  digitalWrite(LED[17], LOW);
 }
 
 if (val2 >= 19){               
  digitalWrite(LED[18], HIGH);
 }
 else{
  digitalWrite(LED[18], LOW);
 }
 
 if (val2 >= 20){               
  digitalWrite(LED[19], HIGH);
 }
 else{
  digitalWrite(LED[19], LOW);
 }
 
 if (val2 >= 21){               
  digitalWrite(LED[20], HIGH);
 }
 else{
  digitalWrite(LED[20], LOW);
 }
 
 if (val2 >= 22){               
  digitalWrite(LED[21], HIGH);
 }
 else{
  digitalWrite(LED[21], LOW);
 }
 
 if (val2 >= 23){               
  digitalWrite(LED[22], HIGH);
 }
 else{
  digitalWrite(LED[22], LOW);
 }
 
 if (val2 >= 24){               
  digitalWrite(LED[23], HIGH);
 }
 else{
  digitalWrite(LED[23], LOW);
 }
 
 if (val2 >= 25){               
  digitalWrite(LED[24], HIGH);
 }
 else{
  digitalWrite(LED[24], LOW);
 }
 
 if (val2 >= 26){               
  digitalWrite(LED[25], HIGH);
 }
 else{
  digitalWrite(LED[25], LOW);
 }
 
 if (val2 >= 27){               
  digitalWrite(LED[26], HIGH);
 }
 else{
  digitalWrite(LED[26], LOW);
 }
 
 if (val2 >= 28){               
  digitalWrite(LED[27], HIGH);
 }
 else{
  digitalWrite(LED[27], LOW);
 }
 
 if (val2 >= 29){               
  digitalWrite(LED[28], HIGH);
 }
 else{
  digitalWrite(LED[28], LOW);
 }
 
 if (val2 >= 30){               
  digitalWrite(LED[29], HIGH);
 }
 else{
  digitalWrite(LED[29], LOW);
 }
 
 if (val2 >= 31){               
  digitalWrite(LED[30], HIGH);
 }
 else{
  digitalWrite(LED[30], LOW);
 }
 
 if (val2 >= 32){               
  digitalWrite(LED[31], HIGH);
 }
 else{
  digitalWrite(LED[31], LOW);
 }
 
 if (val2 >= 33){               
  digitalWrite(LED[32], HIGH);
 }
 else{
  digitalWrite(LED[32], LOW);
 }
 
 if (val2 >= 34){               
  digitalWrite(LED[33], HIGH);
 }
 else{
  digitalWrite(LED[33], LOW);
 }
 
 if (val2 >= 35){               
  digitalWrite(LED[34], HIGH);
 }
 else{
  digitalWrite(LED[34], LOW);
 }
 
 if (val2 >= 36){               
  digitalWrite(LED[35], HIGH);
 }
 else{
  digitalWrite(LED[35], LOW);
 }
}
void loop()
{
 val1 = analogRead(potPin);
 val2 = analogRead(potPin);
 val1 = map(val1, 0, 1023, 0, 180);
 val2 = map(val2, 0, 1023, 0, 36);

 servoPin.write(val1);

 for (int i = 0; i < sizeof(LED) / sizeof(LED[0]); ++i) {
    digitalWrite (LED[0], val2 >= i + 1);
 }

or probably even simpler...

you sir are an absolute jenious!!! i compiled it, and it worked, but i cant test it... i don't have an arduino mega yet... :-[

now the only thing i need is transistors... can you guys recommend some dip packages of transistors... i would like anywhere between 5 and 10 transistors per package...

Have a look at your code again Richard. It will not compile as is, you do not declare your variables, nor do you hint on what they ought to be.

Then there is this part:

if (55 - (val / 5)) = pinnbr {
    outval = HIGH;
 }

It looks as if you assign the value of "pinnbr" to an expression? This is not valid C-syntax. There may be some good intention here, but it's certainly hard to spot.

For a guy who is 11 years old, I'm pretty impressed by his skills and ability to stay focused through some "challenging" advice.

Is the "protocal" the same for these? As in do I still use a 1k ohm resistor between the base and arduino?

I still haven't decided on one yet, but i want them with all normal npn transistors. I am still reading the datasheets.

i compiled it, and it worked, but i cant test it...

Compiled != worked.

You have much to learn, my young padawan. :wink:

(Keep it up!)

... and sometimes forget which ones use == vs. = for comparison.

If you fix that, there is still an issue with parentheses. As written, the conditional expression in your code is "(55 - (val / 5)). In "C" you need to enclose the full conditional expression in parentheses.

So I think I will get the ULN2004A's. If I am correct, the left pins (pins 1-7) are the base, the right pins (pins 10 - 16) are the collectors, and pin 9 is the common emitter? Please tell me if I am right.

Ok, so I found these:

They are cheap, and they look like they should work. From what I understand, the ULN2801A is for use with external ressitors, and the ULN2803A is for use with 5 volt signals? Please correct me if I am wrong.

Also, what would I hook the common load connection to? Would it be 5 volts because that's what I am driving my led's with?

Yay! I am finally understanding! LOL!

It's a website called Newark, I'm sure you have heard of it?

And as far as FINDING then, i just Google searched "transistor array" and went into images. Then i found a schematic that I liked, and looked up the corresponding IC in google shopping. http://computerchristmas.com/tmp/myimages/7-2803.jpg

i searched it in gogle shopping, and thay actually ahve it cheapest... but i know what you mean... i wanted some crystal oacillators, and they had em super cheap! the catch was that they were going to charge me a $25 fee just to get them off of the stupid shelf! i said forget that!

Alright, so I finished the Fritzing design... It took me 2 dsya and a total of over 12 hours!

Can someone tell me how i pulpad the JPG image? I am prety sure that I have to upload it to photobucket or flickr or some other photo server?