Pages: [1]   Go Down
Author Topic: Killer code?  (Read 321 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

I have been coding animations for my arduino powered LED cube recently and I seem to have come across a bit of code that killed my diecimila.

Code:
long Random;
////////////////0 1 2 3 4 5 6 7 8  9  10 11
//int pins[] = {2,3,4,5,6,7,8,9,10,11,12,13};

int pins[] = {2,6,10,3,7,13,4,8,12,5,9,11};
int time = 10;
int time2 = 250;
int time3 = 0;
int time4 = 100;

void setup()
{
  pinMode(pins[0], OUTPUT); //2 g  
  pinMode(pins[1], OUTPUT); //3 3
  pinMode(pins[2], OUTPUT); //4 6
  pinMode(pins[3], OUTPUT); //5 9
  pinMode(pins[4], OUTPUT); //6 g
  pinMode(pins[5], OUTPUT); //7 2
  pinMode(pins[6], OUTPUT); //8 5
  pinMode(pins[7], OUTPUT); //9 8
  pinMode(pins[8], OUTPUT); //10 g
  pinMode(pins[9], OUTPUT); //11 1  
  pinMode(pins[10], OUTPUT); //12 4
  pinMode(pins[11], OUTPUT); //13 7
  
  //Serial.begin(9600);
}

void loop()
{

//START Moving Walls

digitalWrite(pins[0], LOW);
digitalWrite(pins[1], HIGH);
digitalWrite(pins[2], HIGH);
int c = 3;

while(c<=9)
{
for(int l = 0; l<=2; l++) //Controls which layer is lit
{

for(int i =c; i < i+3; i++)
  {
    digitalWrite(pins[i], HIGH);
    digitalWrite(pins[i], LOW);
  }
  
 digitalWrite(pins[l], HIGH); //Increments layer in voltage
 if(l != 2)
 {
 digitalWrite(pins[l+1], LOW);
 }
 else
 {
   digitalWrite(pins[0], LOW);
 }
 
}
c = c+3;
delay(time2);
if(c > 9)
{
  c=3;
}
  
}

  
//END Moving Walls
}
 


After running that bit of code my arduino has stopped accepting new uploads. It runs(with a quick flash of my LEDs) when I first power up the arduino, but I cannot do anything else.  I just get the error stk500_recv(): programmer is not responding      

So, was it my code that did it or did I just get a borked piece of hardware? I use very similar code in other animations(in fact I mostly just changed a timing variable I think).  I'm on 10.5.4 with the latest arduino software.
Logged

Seattle, WA
Offline Offline
Jr. Member
**
Karma: 0
Posts: 81
Arduino rocks my socks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You can't say something like
Code:
for(int i =c; i < i+3; i++)

because i will always be less than i + 3.  Instead do something like
Code:
for(int i =c; i < c + 3; i++)
  {
    digitalWrite(pins[i], HIGH);
    digitalWrite(pins[i], LOW);
  }

This shouldn't kill your board though, try loading the blink example sketch, verifying it, then pressing the reset button on the Arduino right after you press the upload button (or at the same time?).
« Last Edit: September 03, 2008, 03:02:06 am by acleone » Logged

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

Gah, that makes perfect sense, I can't believe I didn't see that one.

I've tried loading up the default sketches and pressing the reset button, it still gives me the error. Right now the led on pin 13 just blinks like crazy, but it isn't the blink sketch.

Thanks for your help, I might try doing a bitbang burn of the bootloader later today if I can figure out how to set it all up.
Logged

Pages: [1]   Go Up
Jump to: