I attempted to write a very simple sketch to blink the three on-board LEDs on a Zero.
EXPECTED
Time L Tx Rx
0 sec
1 sec ON
2 sec
3 sec ON
4 sec
5 sec ON
6 sec
7 sec ON
8 sec
9 sec ON
ACTUAL
Time L Tx Rx
0 sec
1 sec ON
2 sec ON
3 sec ON ON
4 sec ON
5 sec ON ON
6 sec
7 sec ON
8 sec ON
9 sec ON ON
The problem with the actual results is that the L LED stays on when it shouldn't.
Can anyone figure out what’s happening here? Thanks.
Here is my code:
/*============================================
Blink the three on-board LEDs in sequence
============================================*/
#include "Arduino.h"
#define LED_CNT 3 // number of on-board LEDs:
// define an array of the on-board LEDs:
int ledPin[] = {
PIN_LED, // labeled "L" on the board:
PIN_LED3, // labeled "TX" on the board:
PIN_LED2 // labeled "RX" on the board:
};
int led = 0;
void setup() {
// initialize each pin as an output:
for (int i = 0; i < LED_CNT; i++)
pinMode( ledPin[ i ], OUTPUT );
}
void loop() {
// clear all LEDs:
for (int i = 0; i < LED_CNT; i++)
digitalWrite( ledPin[ led ], LOW );
// blink the selected LED:
delay(1000);
digitalWrite( ledPin[ led ], HIGH );
delay(1000);
// choose next LED:
led += 1;
if ( led >= LED_CNT ) led = 0;
}