marquee help

hello everyone, i am going through the tutorials that came with my redboard and need a little help.
I’m trying to make 2 led’s light up then off in order and then reverse order but i don’t understand how to incorporate two “if” statements.
i tried calling one statement “marquee” and the second “marquee2” in the “void loop();” section…but maybe i’m doing it wrong?
thanks everyone!

chase_leds_BA.ino (827 Bytes)

Please post your code correctly, paste it between the statements that pop up when you press the </> icon because most mobile devices can’t cope with a .ino file.

The function is called loop NOT void loop. The void just means it returns no value.

You incorporate two statements in an if by using either the && AND operation or the || OR operation. Where && means both statements have to be true for the if to be true and with || either statement has to be true for the if to be true.

More specific help whe. I can see your code.

int ledPins[] = {2,3,4,5,6,7,8,9};

 setup() {
  int index;
 for(index = 0; index <= 7; index++)
 {
  pinMode(ledPins[index],OUTPUT);
 }
}


loop() 
{
  marquee();
  marquee2();
}

 marquee()
{
  int index;
  int delayTime = 200; 
                       
}
  
  
  for(index = 0; index <= 6; index++) 
  {
    digitalWrite(ledPins[index], HIGH);    
    digitalWrite(ledPins[index+1], HIGH);  
    delay(delayTime);                      
    digitalWrite(ledPins[index], LOW);     
    digitalWrite(ledPins[index+1], LOW);   
  }

  marquee2()
    for(index = 6; index <= 0; index--)
  
    digitalWrite(ledPins[index], HIGH);    
    digitalWrite(ledPins[index+1], HIGH); 
    delay(delayTime);                     
    digitalWrite(ledPins[index], LOW);     
    digitalWrite(ledPins[index+1], LOW);   
}

i’ll have to read up on that other information…i just want it to run one if statement, then once it runs through once, start the second if statement…not where both statements have to be true to run the code.

Hi, what condition will these if statements be conditional on?

Your code is a mess, I'm afraid. Your brackets {} are all over the place for example.

Paul

'm trying to make 2 led's light up then off in order and then reverse order

Will that code even compile?

In order to see a flash you need a delay after each pair of digitalWrite commands, because you set them at one state, delay, set them at the other state and within less than a microsecond go round the loop and put them at the previous state. So you will not see any change.

I don't see why you need any if statement. You will not see much reversing the order it will look the same.

okay, thank you, i was just fooling around a little bit. i am still very new to this, so i'm sorry for the craziness. i just figured that the "if" statement would run an algorithm adding a light and turning off a light until the last light came on. then, once that happened make it where another "if" statement did the same thing but backwards. turn the last two lights on, then off, all the way until the first light turns on..then loop.

and i believe the marquee already has the delay time built into it.

i'm sure my brackets are crazy, but every time i try to verify the program something comes up like..

error: expected constructor, destructor, or type conversion before ';' token

thanks again!

Can you just explain in plain English what you want to happen step by step. Don't try to use any of the new terms you are learning.

Please use the auto-formatting feature in your Arduino IDE (Ctrl+T) before posting your code. This will make it easier to see, where braces are missing or where there are too many of them. And then, you should take a look at some beginners tutorials to learn how to make and use functions.

i just figured that the "if" statement would run an algorithm adding a light and turning off a light until the last light came on. then, once that happened make it where another "if" statement did the same thing but backwards. turn the last two lights on, then off, all the way until the first light turns on..then loop.

OK back to basics then. That is not what an if statement does. An if statement runs a section of code if a certain condition applies. The condition is basically a comparison between variables and is restricted to combinations of equal to, not equal to, greater than or less than.

here is the ctr+T version you asked for.
in my SIK guide i was doing the fourth tutorial where you have eight LEDs.
one of the functions in this particular tutorial is called “marquee”.
basically it looks like the led’s chase each other. one through eight and then repeats.
I decided I would try to make it do something else by making the LEDs light up one through eight, then backwards (eight through one), then repeat.

I understand the “if” statements are where “if step one is true proceed to step two, etc…until a statement is false”.
I just thought you could have one if statement run, then once it gets to the end of its loop, the next code would run which would be another if statement. I don’t want both if statements to run at the same time, just the first, until LED 8 comes on, then go down to the next if statement that will start with LED 8 and work its way to LED 1.
If the if statement in itself is a loop and will always continue, then I will have to find another approach.

In the code below I thought maybe i could name the two if statements “marquee” and “marquee2” put that in the “loop” section, then maybe the code would run “marquee” then “marquee2” in a loop.

thanks again!

int ledPins[] = {2, 3, 4, 5, 6, 7, 8, 9};

setup() {
  int index;
  for (index = 0; index <= 7; index++)
  {
    pinMode(ledPins[index], OUTPUT);
  }
}


loop()
{
  marquee();
  marquee2();
}

marquee()
{
  int index;
  int delayTime = 200;

}


for (index = 0; index <= 6; index++)
{
  digitalWrite(ledPins[index], HIGH);
  digitalWrite(ledPins[index + 1], HIGH);
  delay(delayTime);
  digitalWrite(ledPins[index], LOW);
  digitalWrite(ledPins[index + 1], LOW);
}

marquee2()
for (index = 6; index <= 0; index--)

  digitalWrite(ledPins[index], HIGH);
digitalWrite(ledPins[index + 1], HIGH);
delay(delayTime);
digitalWrite(ledPins[index], LOW);
digitalWrite(ledPins[index + 1], LOW);
}

They are not called if statements, they are called functions. There are no if statements in that code.

None of the functions in that code are defined correctly. A function definition starts with the variable type it returns, if it returns no variable then the word void is used. Then the function name follows and then the variables passed to it are in brackets. Next is the opening brace, then the lines that make up the function and finally a closing brace.

Your code does not follow this and so it will not compile.

http://playground.arduino.cc/Code/Function

https://startingelectronics.org/software/arduino/learn-to-program-course/15-functions/