Pages: [1]   Go Down
Author Topic: Program doesn't loop  (Read 341 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

Hi,
i'm new to this forum and arduino programming. I've got an arduino atmega1280 and i wrote a program for leds that are connected to pins from A0 to A15. Leds flash as they suppose to but then the loop comes to the end it stops. Please help. Here's the program:

int t1=456;
int t2=1254;
int t3=6451;
void setup(){
  for (int i=A0; i<=A15; i++) {
    pinMode(i, OUTPUT);
  }
}

void loop() {
  for (int i=A0; i<=A15; i++) {
    if (t1%2>0) {
      digitalWrite(i, HIGH);
    }
    else {
      digitalWrite(i, LOW);
    }
    t1=t1/2;
  }
  delay(1000);
  for (int i=A0; i<=A15; i++) {
    if (t2%2>0) {
      digitalWrite(i, HIGH);
    }
    else {
      digitalWrite(i, LOW);
    }
    t2=t2/2;
  }
  delay(1000);
  for (int i=A0; i<=A15; i++) {
    if (t3%2>0) {
      digitalWrite(i, HIGH);
    }
    else {
      digitalWrite(i, LOW);
    }
    t3=t3/2;
  }
  delay(1000);
}
Logged

Offline Offline
Sr. Member
****
Karma: 9
Posts: 254
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The second time your program enters the loop t1,t2,t3 all retain their value from the first loop. You halve each one each time, and so they all tend to 0, and all the lights turn off. What is this program meant to do? It looks like you're trying to output your number in binary, is that right?
Logged

Johannesburg. UTC+2
Offline Offline
Faraday Member
**
Karma: 82
Posts: 3865
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Good case for sprinkling serial writes strategically into your code so you can see where it actually goes and what various values are.
Logged

The Elders of the Internet know who I am.....

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

Thanks for replies. Just solved the problem. As tobyb121 mentioned the program uses the t1,t2,t3 values from the first loop. So i moved the values to the loop section and everything is okey smiley
Again Thanks for replies smiley
Logged

Pages: [1]   Go Up
Jump to: