#define LED_NUM 8 /* Number of user LEDs */
const unsigned long led_mask[] = { 1UL<<0, 1UL<<1, 1UL<<2, 1UL<< 3,
1UL<< 4, 1UL<< 5, 1UL<< 6, 1UL<< 7 };
int idxCur = -1; /* current led position from 0..7 */
int idxOld = 0; /* old led position from 0..7 */
int dir = 1; /* direction for switching the LED */
/**
* @brief Function that initializes Button INT0
*/
void BUTTON_init(void) {
LPC_GPIO2->FIODIR &= ~(1 << 10); /* PORT2.10 defined as input */
LPC_GPIOINT->IO2IntEnF |= (1 << 10); /* enable falling edge irq */
NVIC_EnableIRQ(EINT3_IRQn); /* enable irq in nvic */
}
/**
* @brief Function that initializes LEDs
*/
void LED_init(void) {
LPC_GPIO2->FIODIR = 0x000000FF; /* LEDs on PORT2 defined as Output */
/* Calculate 'idx': 0,1,...,LED_NUM-1,LED_NUM-1,...,1,0,0,... */
idxCur += dir;
if (idxCur == LED_NUM){ dir = -1; idxCur -= 2; }
else if (idxCur < 0) { dir = 1; idxCur += 2; }
LED_Off(idxOld); /* switch off old LED position */
LED_On (idxCur); /* switch on current LED position */
idxOld = idxCur;
}
/**
* @brief Main Function
*/
int main (void)
{
SystemInit(); /* initialize system */
LED_init();
idxCur = 0;
idxOld = 0;
dir = 1;
LED_On (idxCur); /* switch on first LED */