How to toggle one RGB LED after another with the SW2 and SW3 from frdmk64f?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to toggle one RGB LED after another with the SW2 and SW3 from frdmk64f?

1,432 Views
paper
Contributor I

Hi, I'm very new to this forum. So I apologize if this isn't the right thread or sub-thread. Basically, I'm experimenting and trying to learn new things with the Frdmk64f. I'm basically trying to get SW2 toggle one color LED and by pressing SW3 should toggle another color LED. And when both LED are ON, the LED will blend the two color.
Here's what I got so far: 

#include <stdio.h>
#include "board.h"
#include "peripherals.h"
#include "pin_mux.h"
#include "clock_config.h"
#include "MK64F12.h"
#include "fsl_debug_console.h"

void BOARD_SW2_IRQHANDLER(void) /*Interrupt Service Routine for SW2*/
{
uint32_t flags = GPIO_PortGetInterruptFlags(BOARD_SW2_GPIO); /*get triggered interrupt flag*/
GPIO_PortClearInterruptFlags(BOARD_SW2_GPIO, flags); /*clear triggered interrupt flag*/
LED_RED_ON(); /*turn ON RED LED*/
}
void BOARD_SW3_IRQHANDLER(void) /*Interrupt Service Routine for SW3*/
{
uint32_t flags = GPIO_PortGetInterruptFlags(BOARD_SW3_GPIO); /*get triggered interrupt flag*/
GPIO_PortClearInterruptFlags(BOARD_SW3_GPIO, flags); /*clear triggered interrupt flag*/
LED_RED_OFF(); /*turn OFF RED LED*/
}

int main(void) {

/* Init board hardware. */
BOARD_InitBootPins();
BOARD_InitBootClocks();
BOARD_InitBootPeripherals();
/* Init FSL debug console. */
BOARD_InitDebugConsole();

PRINTF("Hello World\n");

/* Force the counter to be placed into memory. */
volatile static int i = 0 ;
/* Enter an infinite loop, just incrementing a counter. */
while(1) {
i++ ;
/* 'Dummy' NOP to allow source level single stepping of
tight while() loop */
__asm volatile ("nop");
}
return 0 ;
}

0 Kudos
Reply
1 Reply

1,398 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi

Please refer to the gpio demo in SDK. The demo uses the button to control/toggle the LED

SDK_2.9.0_FRDM-K64F\boards\frdmk64f\driver_examples\gpio\input_interrupt

 

Regards

Daniel

0 Kudos
Reply