Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
9 years, 10 months ago.
Sample program to make blink and externally connected LED
Hi, can anybody give me a sample program to make an LED blink which is externally connected to the pins. And the uc is lpc1768.
1 Answer
9 years, 10 months ago.
Hi Sachin. Which pin have you used for the LED ? Please share this detail. Do you have an external LED attached with the current limit resistor ?
Also, there is an onboard LED already on your LPC1768 so you do not need to work too hard on this. You will need to import the program referenced here:
https://developer.mbed.org/teams/mbed/code/mbed_blinky/
Be sure that the PLATFORM (see the top right corner of the compiler page) matches your target board. If not, then this needs to be corrected by adding a platform and then select your development board and make this your default.
Once you compile, the compiled file will be labelled something like:
blinky_LPC1768_xxxx, etc. so you can drag and drop onto the correct target board. You have a very popular development board.
Update:
Have you been able to import the above code ? Select the BLUE BOX (IMPORT THIS PROGRAM) on the right side of the posted code example and the compiler will automatically import into your personal cloud drive. Then proceed to hit the + key for the BLINKY project and select the MBED label and then select UPDATE (right side of the screen). This will update the MBED library to the latest since the posted code is a bit old.
Be sure the target board / platform matches your LPC1768 and proceed to compile and then drag & drop the code onto your drive letter. The LED should start blinking on your LPC1768 board.
Here is the code (depends on the MBED library) that will flash the LED:
- include "mbed.h"
DigitalOut myled(LED1);
int main() { while(1) { myled = 1; LED is ON wait(0.2); 200 ms myled = 0; LED is OFF wait(1.0); 1 sec } }
I actually did not connect the resistor. And i used pin5 for my external LED. But i got a sample code from the 'code' section. Thanks for the information.
posted by 06 Jan 2016Review the schematic for your LPC1768 board from here:
https://developer.mbed.org/media/uploads/chris/mbed-005.1.pdf
If you wish to add an external LED, this is fine but note the use of the current limit resistor which is required else you can damage the microcontroller pin and/or the attached LED. The resistor value is not super critical but recommend a value of 100-500 ohms (lower = higher current and respectively will be brighter and also put more strain on the micro pin). A good value is 330 or 390 ohms.
Note the LED orientation as there is a polarity. The ANODE (back of the LED arrow head) is positive and the other side is the cathode. So if you apply the resistor to +3.3 volts and then the other side of the resistor to the ANODE of the LED and the CATHODE to the micro pin #5 of the module, you are in CURRENT SINK mode. This means that when the P1.0 (pin 5 of the module) is LOW, you have applied a GROUND to the LED and the LED will be ON. If you configure the P1.0 pin to be HIGH, your LED will be OFF.
To use pin 5 of the module with your external LED (and resistor must be there as noted), use the following:
https://developer.mbed.org/handbook/DigitalOut
so the following should work (not tested):
- include "mbed.h"
DigitalOut myled(p5); change this pin value to suit if using another pin on the module
int main() { while(1) { myled = 1; wait(0.2); myled = 0; wait(0.2); } }
BTW - here are more details on your board:
https://developer.mbed.org/handbook/mbed-NXP-LPC1768-Getting-Started
-----
Documentation not ready - means that your MBED library is old and needs to be updated. See here for more details:
https://developer.mbed.org/forum/bugs-suggestions/topic/5191/?page=1#comment-39536
Locate the MBED library inside your tree (hit the + key inside the project to expand the tree) - then highlight the MBED library file and right mouse click and select UPDATE (see right side of the compiler). This process will update the MBED library -> save and recompile. This should fix the error.
-----
Documentation out of date - goto the top of your project and select with your mouse - right mouse click and you will see a drop down menu - select the UPDATE option from this menu. This should resolve the error. Test it and report your results.
-----
Sachin - there is a compiler bug that the MBED is reviewing related to this same error code of "Documentation out of date". Do not worry about this documentation issue for your project. The key requirement is that you want to UPDATE the MBED library to allow for the compiler to compile correctly. The documentation out of date should only be treated as a warning at this time.
See here for more details of the bug being reviewed by the MBED team:
https://developer.mbed.org/forum/bugs-suggestions/topic/17265/
v
posted by 06 Jan 2016