Go Down

Topic: [Solved] LED bar...but inverted !? (Read 770 times) previous topic - next topic

HoodieNL

Dec 20, 2009, 12:02 am Last Edit: Dec 20, 2009, 09:52 pm by HDLM Reason: 1
:-?

Hi all, im new here and new to the world of microcontrollers.
So what did i do; i bought a arduino board to play around with. Nothing difficult, nothing specific.

So i found this knight rider thingie on this forum somewhere in an old topic. I upped the code to the arduino, wired the leds n resistors up the way i should and......

....the LEDs do light up, and the knight rider effect is running...but its inverted. What i mean is that there should be a light running from left to right and vice versa....but in my case al lights are on and one goes off from left to right and vice versa...

This is the code i used...:

Code: [Select]
int ledpin[] ={3,5,6,9,10,11};
int n = 0; //speed counter.
int i =0; // repeater.
int value[] ={0,0,0,0,0,0};

void setup()
{
}

void loop()
{
 if(n == 100){value[0]=255;}
 if(n == 200){value[0]=255;}
 if(n == 300){value[1]=255;}
 if(n == 400){value[2]=255;}
 if(n == 500){value[3]=255;}
 if(n == 600){value[4]=255;}
 if(n == 700){value[5]=255;}
 if(n == 800){value[5]=255;}
 if(n == 900){value[4]=255;}
 if(n == 1000){value[3]=255;}
 if(n == 1100){value[2]=255;}
 if(n == 1200){value[1]=255;}
 if(n >= 1200){n =0;}
 
 
 for (i  = 0; i <=5; i++)
 {
   if(value[i] >= 5){ value[i]-=1;}
   else if (value[i] < 5) { value[i]=0;}
 }

for (i  = 0; i <=5; i++)
  {
    analogWrite(ledpin[i], value [i]);
  }
  n+=5;
  delay(5);
}





Examples:

This is what i have
[media]http://www.youtube.com/watch?v=o4sqLxfkfdg
[/media]
This is what it should be
[media]http://www.youtube.com/watch?v=uES0qpk5Ye4[/media]

So the code works and the hardware is connected properly...what can i do to fix it ?



bill2009

This is pretty crufty because I don't "get" the code that's there but if the lights are all the opposite of what you want, just change the analogWrite to be 255-value .  May not be clean but maybe it will move you along.

Coding Badly

How are the LEDs wired?  

Pin to resistor to LED then to ?

Pin to LED to resistor then to ?

HoodieNL

The leds are wired like this example:

http://hdlm.eu/61933851_3b9a25ab42_o.jpg

I used the same amount of leds in my setup (6 pcs) and i wired htem up exactly the same way. The only thing that i did different is that i used an additional 6 LEDs to mirror the sequence, so every pin switches 2 LEDs instead of just 1.

Coding Badly

#4
Dec 20, 2009, 08:27 pm Last Edit: Dec 20, 2009, 08:31 pm by bcook Reason: 1
I can't tell from the picture if the black wire is connected to GND or 5V.  You didn't answer my questions so I'll assume you don't want to continue discussing how the circuit is wired.

I can't see any problems with your Sketch.  Unless someone else can spot a problem, I guess you're stuck with an inverted Knight Rider.

HoodieNL

Quote
You didn't answer my questions so I'll assume you don't want to continue discussing how the circuit is wired.


I didn' t answer your question ?  :-?

If, by that, you mean that i did not write down the answer, you' re right...i did, however, provide you with a graphical answer on which you can see how the wiring is set up...

...So, to put it your way: I'll assume you don't know the answer to the question i asked in this discussion...but you simply don't want to admit it !

So, maybe there is another user on this board that can help me out..!?

AWOL

Quote
I can't tell from the picture if the black wire is connected to GND or 5V
Neither can I.

Quote
So, maybe there is another user on this board that can help me out..!?
Not until you answer the question of how it is wired up, no, I think it unlikely.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

HoodieNL

:-/

Wow...i think its just the fact that english is not my native language.
I cant understand what the ' answer'  is that you both want...

The answer about the wiring is right there, on the picture... :-/
It would never be connected the GND pin would it ? So its either 5v or 3v, isnt it ?

----------------------------------------------------------------------------

Anyway, i ' fixed'  the problem by using another code. The new code is alot more simple but the downside is that it isnt as smooth as the first one i used. I inserted the code below, as it might be handy for others int he future...

I dont think i will be coming back to this board with another question as i find the reactions of certain users are ' asking about the obvious' and not very friendly....thanks for the help, or trying to help though.

Good luck

Code: [Select]
void setup(){
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
}

void loop(){
digitalWrite(3, LOW);
delay(80);
digitalWrite(2, HIGH);
delay(80);
digitalWrite(4, LOW);
delay(80);
digitalWrite(3, HIGH);
delay(80);
digitalWrite(5, LOW);
delay(80);
digitalWrite(4, HIGH);
delay(80);
digitalWrite(6, LOW);
delay(80);
digitalWrite(5, HIGH);
delay(80);
digitalWrite(7, LOW);
delay(80);
digitalWrite(6, HIGH);
delay(80);
digitalWrite(8, LOW);
delay(80);
digitalWrite(7, HIGH);
delay(80);
digitalWrite(7, LOW);
delay(80);
digitalWrite(8, HIGH);
delay(80);
digitalWrite(6, LOW);
delay(80);
digitalWrite(7, HIGH);
delay(80);
digitalWrite(5, LOW);
delay(80);
digitalWrite(6, HIGH);
delay(80);
digitalWrite(4, LOW);
delay(80);
digitalWrite(5, HIGH);
delay(80);
digitalWrite(3, LOW);
delay(80);
digitalWrite(4, HIGH);
delay(80);
digitalWrite(2, LOW);
delay(80);
digitalWrite(3, HIGH);
delay(80);
}

Groove

#8
Dec 21, 2009, 08:57 am Last Edit: Dec 21, 2009, 08:58 am by GrooveFlotilla Reason: 1
Quote
It would never be connected the GND pin would it ? So its either 5v or 3v, isnt it ?
Quite often what may seem obvious to you is not what most people would expect.
A LED can be connected between a digital output and GND, in which case writing a '1' to the pin will source current through the LED and light it.
If you connect the LED between 5V and the pin, writing a '0 will sink current through the pin, and light the LED.

Quote
i find the reactions of certain users are ' asking about the obvious' and not very friendly
People ask questions because noobs often don't give the whole picture.
They write something like "it isn't working" or "it doesn't do what it is supposed to" or "I wired it up correctly", but without a clear idea of what the program was supposed to do, the rest of us can't possibly give clear sensible answers.
If you get asked for your code, don't just post the bit that you think is wrong; post it all.
If you get asked for a schematic, makes sure it's a clear one.

This is a very knowledgeable and friendly forum, but if someone asks you for more detail, if you want an answer, you'd better provide it.
Per Arduino ad Astra

Go Up