Go Down

Topic: Program doesn't loop (Read 434 times) previous topic - next topic

robias7

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);
}

tobyb121

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?

JimboZA

Good case for sprinkling serial writes strategically into your code so you can see where it actually goes and what various values are.
Arduino ethernet server here.... http://jimboza.gotdns.com:8085/

No PMs for help please

robias7

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 :)
Again Thanks for replies :)

Go Up