simple question

If you put {} instead of () on those else statements then they make even less sense.

else {cur==1;}

How is a comparison all by itself useful? If cur was 1 this would become:

else {true;}

What usefulness is there to that line? It does nothing.

Did you mean to assign the value of 1 to cur here? Why? So when you get to step 2 the if (cur == 1) fails and it sets cur back to 1 on that else. So you'll just keep running step 1 over and over.

Maybe you should take a break from it. You sound frustrated. Do some C++ tutorials for a little while and get accustomed to the language. It will really help you a lot.

i think i actually found the reason why i didn't get the reason of this variable. Please take a look at your example for me. You did change the value of the variable there, in the if statement. Maybe it was a typo, but you set cur to 1 in the statement. That is why i have been trying to understand why i keep doing that and it fails.

*P.S. I am a little frustrated, i'm trying to keep it cool though. It's 3:20 AM where i live, at 9 AM is my first day of college, i need to finish this thing up by then, add 3 voltmeters and one ammeter or something like that, and if i have enough time i should take a shower or something before i get there. I am sorry if i messed your mood, didn't mean to do that.

Yup, did it that way on purpose. Look where that assignment is, it's inside the timing code. SO it says

if the state is state 1 then:

Check the time and IF the time is up:

Do the thing and move to step 2.

So you only move to step 2 if the time is up on the thing in step 1. If the time is NOT up yet then it would stay at step 1 and the next time loop runs we'll go into that if again and check the timing on step 1 again.

If you would format the code so you can see the logic that might be a little more apparent. Cramming it all together in few lines and right up against the margin makes your logic harder to see.

This is what you sent :

int step = 0;

void loop(){

if(step == 0){ if(current - previous >= interval){ // do whatever previous = current; step = 1; } } else if(step == 1){

This is what i should do ? :

int step = 0;

void loop(){

if(step == 0){ if(current - previous >= interval){ // do whatever previous = current; step == 1; } } else if(step == 1){ if(current-previous>=interval) { //do whatever ; previous=current ; step==2;} else if(step == 2){ if(current-previous>=interval) { //do whatever ; previous=current ; step==3;}

etc ? This doesn't seem to work. haven't tried it yet, but i am checking on that variable twice, not changing it once, how is that supposed to help ?

step == 1;

For the love of God, please STOP what you are doing and go learn the freaking difference between = and ==. We've mentioned it several times in this thread. You're not going to get this working until you do. Just stop, totally stop working on this and go learn that. It's getting frustrating telling you over and over again only to be ignored.

ALSO:

else if(step == 1){ if(current-previous>=interval) { //do whatever ; previous=current ; step==2;}

Like I have mentioned at least twice in this thread, don't jam it all into one line like that. See how much easier it is to follow the flow with the indented blocks in the part I wrote. Format the freaking code. Just do it. If you still don't understand why then just do it because I said I'm not going to try to read any more of your code if you don't.

I don't like having my advice ignored. Continue doing so and I will stop giving it.

void loop(){

   if(step == 0){
       if(current - previous >= interval){
           // do whatever
           previous = current;
           step == 1;  //<<< WHY did you change this to useless?
       }
   }

For Christ’s sake, I just noticed that you even changes that line in the part I wrote. Why did you do that? How frustrating! I write it correctly, you come and change it and then complain that it doesn’t work. Well no freaking wonder it doesn’t work.

I’m starting to think you’re just trolling me.

I said twice that i don't see a reason for that, that it is useless. First i asked you if you made a typo there, you kept telling me i should have == instead of = somewhere. After that you said you did it on purpose, and i was like "ok, i will try that out too." than when i gave you your piece of code asking you if that was what you meant, you told me that you want me to format my code. i did that now. calm down, i'm not trolling no one. not in the mood for such things.

long previousMillis = 0;
int gravity = 1000;
int dif = 3000;
int cur = 1;

void setup () {
  DDRD = B11111111;
}

void loop() {

  unsigned long currentMillis = millis();

  if (cur == 1) {
    PORTD = B00011000;
    previousMillis = currentMillis ;
    cur = 2;
  }
  else if (cur == 2) {
    if (currentMillis - previousMillis >= gravity); {
      PORTD = B00010000;
      previousMillis = currentMillis ; cur = 3 ;
    }
  }
  else if (cur == 3) {
    if (currentMillis - previousMillis >= dif); {
      PORTD = B01100000;
      previousMillis = currentMillis ; cur = 4;
    }
  }
  else if (cur == 4) {
    if (currentMillis - previousMillis >= gravity); {
      PORTD = B01000000;
      previousMillis = currentMillis; cur = 5 ;
    }
  }
  else if (cur == 5) {
    if (currentMillis - previousMillis >= dif); {
      PORTD = B10000100;
      previousMillis = currentMillis; cur = 6 ;
    }
  }
  else if (cur == 6) {
    if (currentMillis - previousMillis >= gravity); {
      PORTD = B00000100;
      previousMillis = currentMillis ; cur = 7;
    }
  }
  else if (cur == 7) {
    if (currentMillis - previousMillis >= dif); {
      PORTD = B00011000;
      previousMillis = currentMillis ; cur = 1 ;
    }
  }

}

If this is what you meant, it's not working, and i've already tried it twice.

TraianGrg: you kept telling me i should have == instead of = somewhere.

In the if statements where you want to do a comparison you need to use the comparison operator.

When you want to assign a value you should use the assignment operator.

Do you understand the difference between assigning a value and comparing two values?

TraianGrg: If this is what you meant, it's not working, and i've already tried it twice.

Define not working? What does it do? How does that compare with what you want? Just saying it doesn't work isn't very useful is it?

That code should

  1. Turn on lights on pins 3 and 4
  2. After gravity milliseconds turn off pin 3
  3. After dif milliseconds turn off 4 and turn on 5 and 6
  4. After gravity milliseconds turn off 5
  5. After dif milliseconds turn off 6 and turn on 7 and 2
  6. After gravity milliseconds turn off 7
  7. After dif milliseconds turn off 2 and turn on 3 and 4 and go back to step 1.

When you assign a value you change the initial value of an int.

When you compare it, you don't change anything, you just check the status between the terms, true/false kinda thing.

Like :

int cur=1

if(cur==1) //which is true {cur=3;} //which is changing the value of cur to 3.

Wait, no it won't. Because you added something else to my code. Why do you keep altering what I wrote?

if (currentMillis - previousMillis >= gravity);

Should an if statement have a semicolon at the end? When you put that there it means if(this) then do nothing and the next lines in the braces get executed unconditionally.

Again, I really think you should take a little time to learn the language a little.

If you fix this it will do what I laid out in my last post.