Unknown type name error for LED

I am trying to use LED2 or LED3 in Nucleo F401 board. I am getting error:

/src/main.cpp:3:18: error: unknown type name ‘LED2’
DigitalOut myled(LED2);

Also if I change it to LED1 the code is built, but that specific led doesn’t turn OFF instead it remains On all the time. Hope to get some help here. Thanks

Hello,

this behaviour is correct. You probably used the names what are printed on the PCB but these are not and can not be used in Mbed.

On PCB names:

  • LED1 is just for ST-Link and it is not accessable from MCU
  • LED2 is Mbed LED1 which is accessable from MCU
  • LED3 is only for power indication

BR, Jan

Thanks for that. Does build always compile main.cpp or can I change it to compile any other .cpp file? If so please let me know how

I do not know what you mean but you need a .cpp file where the main function has to be and from user code starts. The name main.cpp it self is not important it is just for better orientation in project because when you see main.cpp then you know - “ok, here is the main function, here user code starts”.

If you want split your code in functions or classes in separete files, then you need another .h and .cpp files what will be included in the main file according to c++ standart.

BR, Jan