Pages: [1]   Go Down
Author Topic: stuck situation  (Read 730 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hi there i have a problem with my code. it is a statement that never seems to be fulfuilled

my settup is 2 push buttons 3 leds and one IR led the ir led is only to transmit information and this is working.
the higlighted part is the on that seems to never end

if ( rod < 1800 ){Serial.println(" if rod statment");
   while( rod != 1800 ){Serial.println(" while rod statment"); delay(500);
     Serial.print(rod);
      digitalWrite(ledPin2, LOW);
      digitalWrite(ledPin, HIGH);
      digitalWrite(ledPin3, LOW);
      //------------------------
      [glow]if(rod == 1799){
       int death = 0;
            while(death != 500){
              digitalWrite(ledPin2, LOW);
              digitalWrite(ledPin, HIGH);
              digitalWrite(ledPin3, LOW);
              delay(50);
              digitalWrite(ledPin2, LOW);
              digitalWrite(ledPin, LOW);
              digitalWrite(ledPin3, LOW);
              delay(50);
              digitalWrite(ledPin2, LOW);
              digitalWrite(ledPin, HIGH);
              digitalWrite(ledPin3, LOW);
              delay(50);
              death = death++;
              sendOver = sendOver + 1;
               if (sendOver == 15){
          dataOut = timesDied;
          int key = 0;
          for (int j = 0; j<10; j++) {
        key = sendIRKey(dataOut);
        }
      Serial.print("Key Sent: ");
      Serial.println(key);
             sendOver = 0;
                }
              }
              if(death == 500){
                gron = 0;
                gul = 1800;
                rod = 1799;
                timesDied = timesDied + 1;
              }
          }
       //------------------------------------  
          rod = rod + 1;
          sendOver = sendOver + 1;
          if (sendOver == timeToSend){
          dataOut = timesDied;
          int key = 0;
          for (int j = 0; j<10; j++) {
        key = sendIRKey(dataOut);
        }
      Serial.print("Key Sent: ");
      Serial.println(key);
        sendOver = 0;
      }
       if( sendOver > timeToSend){
        sendOver = timeToSend -1;
        }
          if (rod > 1800){
            rod = 1799;
            }
      val = (digitalRead(inPin));
    if (val == LOW){Serial.println(" if val statment");
      rod = rod + 50;
      delay(500);
        if(rod > 100 && rod < 2000){
            rod = 1799;
            gul = 1800;
            gron = 1800;
          }
    }
    val2 = (digitalRead(inPin2));
    if (val2 == LOW){Serial.println(" if val2 statment");
      rod = rod + 50;
      delay(500);
       if(rod > 1675 && rod < 2000){
        gul = 0;
        rod = 1800;
        gron = 1800;}[/glow]    }
    }
Logged

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

Hi.

I don't know if this will solve your problem, but I suspect this line:

[size=14]death = death++;[/size]
[/b]

is not incrementing the variable as you expect. Either use "death++" or "death += 1" or "death = death + 1". I tested this idea in a compiler other than Arduino's and found that in fact "death = death++; " does not increment the value of death. Should be some compiler workings of the post-increment.

Anyway, try it and let me know if this helps.

Oscar
Logged

Copenhagen / Denmark
Offline Offline
Edison Member
*
Karma: 6
Posts: 2360
Do it !
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

TRy to closely follow the value of the variable rod.

If it never becomes exactly 1800 then the while loop starting at the very top

while( rod != 1800 ){Serial.println(" while rod statment"); delay(500);

will go on forever.
Logged

Pages: [1]   Go Up
Jump to: