3 years, 11 months ago.

FRDM K64F: Lighting up an external LED

Hello everybody! Here I am again with another noobish question.

I'm trying to perform a few exercises/experiments with my FRDM K64F board and since the kit I'm using was supposed for Arduino, I don't have the correct code to use at my disposal.

Today I was trying to use the board to light up an external led. Here's what I've done: - LED on the breadboard - Grounded one of the pins of the LED - Connected the other pin of the LED to a 220 ohm resistor - Connected the free pin of the resistor to the D12 pin of the board (10-PTD3) - Compiled and loaded on the board the code below

include the mbed library with this snippet

#include "mbed.h"

DigitalOut led(D12);

int main() {
    
led=1;
  
}

Now, of course, the LED is not lighting up. I've tried a few things to solve the problem like changing the ground pin and the output pin. I tried some different code as for example using " led=!led; " for the switch.

I guess I'm really missing something on how DigitalOut is working I guess :/

Thanks for your help and time, and sorry for the noob question :D

1 Answer

3 years, 11 months ago.

I will make some general observations. You seem to be on the right track. Check the devboard and make sure there is nothing else connected to D12 that could be interfering. D12 is grayed out in the pinout diagram. Maybe try D9 instead. Also you probably should not exit main(). Throw an infinite while loop in there, maybe with a call to wait() or Thread::wait().

#include "mbed.h"
 
DigitalOut led(D9);
 
int main() {
   
	while (true) {
		led = !led;
		Thread::wait(1000);
	}
}

Graham

Accepted Answer

Hi! Thank you very much for the help!

The while(true) for the infinite loop was definitely helpful and helped me understand some mistakes I've made in the past.

Probably I was also mistaking the cathode and anode of the LED (sigh).

Thanks again for your time :)

posted by Nicolò Bagarin 09 Nov 2016