Pages: [1]   Go Down
Author Topic: Bar graph animation Help!  (Read 602 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello, I'm a complete noob, and I'm stuck trying to make an 8 leds do a reverse "bar graph aanimation. that is, all 8 start on, and turn of one after another in order, and once the last one is off, they turn back on in the order they turned off... I can already turn one off with my IR control, but would like to achieve this animation when I use my remote.

Any help would be greatly appreciated... I've been googling all over, and found all kinds of info on bar graphs, but not this kind of "animation. Thanks!
Logged

Fort Lauderdale, FL
Offline Offline
Faraday Member
**
Karma: 71
Posts: 6144
Baldengineer
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Stop searching specific to bar graphs.  The bar graph (assuming it is the LED type) is just an array of LEDs.  So you are doing the same thing people do with individual LEDs.

You'll get more help if you post the code you're using now.

Hardware schematics (or drawings) are always helpful too.
Logged

Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.c

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

THanks!   Here is the begining of the code:

circuit:
ir module connected to pin 2(Digital)
led 1-2-3-4-5-6-7-8 connected to pin 3-4-5-6-7-8-9-10
*/

#include

int RECV_PIN = 2;
int led1 = 10;
int led2 = 3;
int led3 = 4;
int led4 = 5;
int led5 = 6;
int led6 = 7;
int led7 = 8;
int led8 = 9;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
Serial.begin(9600);
irrecv.enableIRIn(); // Start the ir receiver
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(led5, OUTPUT);
pinMode(led6, OUTPUT);
pinMode(led7, OUTPUT);
pinMode(led8, OUTPUT);
}

void loop() {


if (irrecv.decode(&results)) {
Serial.println(results.value, DEC);


if(results.value == 16705559)
digitalWrite(led1, HIGH); // Turn LEDs on
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, HIGH);
digitalWrite(led5, HIGH);
digitalWrite(led6, HIGH);
digitalWrite(led7, HIGH);
digitalWrite(led8, HIGH);

if (irrecv.decode(&results)) {
Serial.println(results.value, DEC);
if(results.value == 16656599)
digitalWrite(led1, LOW); // set the LEDs off
digitalWrite(led2, LOW)
digitalWrite(led3, LOW)
digitalWrite(led4, LOW)
digitalWrite(led5, LOW)
digitalWrite(led6, LOW)
digitalWrite(led7, LOW)
digitalWrite(led8, LOW)

irrecv.resume(); // HERE is where I would like LEDS to turn off 1 at a time from 1 to 8 and then back on from 8 to 1 in order one time

if(results.value == 16672919)
digitalWrite(led1, LOW); // turn LEDs off

????

irrecv.resume(); // Receive the next value

}

}
}
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 654
Posts: 50931
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you put each { on it's own line, and use Tools + Auto Format, you'll see that your nested if statements are not going where you think that they should.

Code:
if(results.value == 16705559)
digitalWrite(led1, HIGH); // Turn LEDs on
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, HIGH);
digitalWrite(led5, HIGH);
digitalWrite(led6, HIGH);
digitalWrite(led7, HIGH);
digitalWrite(led8, HIGH);
If you get 16705559, turn led1 on. Regardless of what you get, turn the others on. Is that what you want?

Code:
if (irrecv.decode(&results)) {
You should have only one of these statements in the code.

Code:
irrecv.resume();
This should be at the end of loop(), not embedded in the middle of some nested if statements. You ALWAYS want to do this.
Logged

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

You may find an answer in the BitwiseAnd tutorial found here:

http://arduino.cc/it/Reference/BitwiseAnd

Loop from one to eight, then square the number of the loop and run it through an 8 piece bitwise and operation. I'm doing the same but generating a byte to send to a shift register, using only three pins rather than eight. I got it to work, so far, but it has to be expanded to three bytes and three shift registers to complete my project. In your case, I think expanding this code would do what you require:

Code:
void output_result(const long result) {
  digitalWrite(Led_Bit0, result & B00000001);
  digitalWrite(Led_Bit1, result & B00000010);
  digitalWrite(Led_Bit2, result & B10000000);
}

When I built my loop, the math of the processor resulted in rounding errors, which you may also have happen to you.

Code:
void loop()
{
  //count from 1 to 8 and illuminate appropriate number of LEDs
  for (int lCount = 1; lCount < 9; lCount++)
  {
    //two raised to the power of the count
    //pow() function is double NOT INT!
    //processor rounding errors require additional math applied to number
    double numberToDisplay = (pow(2,lCount) - 1);
    int nTD = ((numberToDisplay*100)+5)/100;

This code generates a byte, to send through the bitwise and operator code above.

I've not checked this in real time, but I think it would work for you.

These snippets of code have come from two different sketches and I've not matched the variable names, but you should see that nTD in the lower sketch is result in the upper one.

I hope you see this post and that it works for you. If so, let me know, as it also helps me with my understanding of the wonderful world of Arduino.
Logged

Pages: [1]   Go Up
Jump to: