I just got my SIK in today, freaking loving it. I've got 10 LEDs wired up in a line with the 330ohm resisters, which is the second example in their guide. First of all, I'm still not comfortable with how the main loop() function reacts with loop inside of it. I've created a function snake(), which basically runs a line of LEDs down the series. I got it working after some effort, but as soon as the snake overruns (and beings to disappear) the series, the third LED turns on. Is it my code, the wiring, or some symptom of overlapping loops?
I've ran the example code for my config, and it works just fine. I've switched out the LED, the wiring, switched the pin. All the same symptom. As soon as the "head" of the snake overflows the LED series, the third bulb, pin 4, lights up, and stays light until the snake passes over it again and it is turned off.
Here is my code:
int ledPins[] = {2,3,4,5,6,7,8,9,10,11};
int length = 4;
int head = 0;
void setup() {
for(int i = 0; i < 10; i++){
pinMode(ledPins[i],OUTPUT);
}
}
void loop() {
snake();
}
void snake() {
int tail = (head-length > 0) ? head-length : 0;
for (int i = 0; i < tail; i++) {
digitalWrite(ledPins[i], LOW);
}
for (int i = tail; i < head; i++) {
digitalWrite(ledPins[i], HIGH);
}
if (tail > 9) {
head = 0;
} else {
head++;
}
delay(500);
}