Pages: [1]   Go Down
Author Topic: [Solved] LED bar...but inverted !?  (Read 740 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 14
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

 :-?

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:
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 ?


« Last Edit: December 20, 2009, 03:52:11 pm by HDLM » Logged

ottawa, canada
Offline Offline
God Member
*****
Karma: 6
Posts: 993
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Bill Rowe
Olduino - An Arduino for the First of Us
www.olduino.wordpress.com

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 209
Posts: 13022
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

How are the LEDs wired?  

Pin to resistor to LED then to ?

Pin to LED to resistor then to ?
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 14
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 209
Posts: 13022
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: December 20, 2009, 02:31:04 pm by bcook » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 14
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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..!?
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 309
Posts: 26482
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

"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.

0
Offline Offline
Newbie
*
Karma: 0
Posts: 14
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

 :-/

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:
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);
}
Logged

UK
Offline Offline
Faraday Member
**
Karma: 17
Posts: 2884
Gorm deficient
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: December 21, 2009, 02:58:27 am by GrooveFlotilla » Logged

Per Arduino ad Astra

Pages: [1]   Go Up
Jump to: