TVZ Mechatronics Team


Zagreb University of Applied Sciences, Professional Study in Mechatronics

Introduction

Note

Each of your programs should contain only one file named main.cpp. Inside your program folder don't add new files with .cpp extension. To create a new program in Mbed compiler you need select New (top left corner of menu bar) and then in the drop down menu select New program .

Solve the following tasks with a goal of getting started with mbed NXP LPC1768 platform:

  1. Read the introduction to the mbed LPC1768 microcontroller. Check if the latest board firmware is installed. If not, update the firmware to the latest revision using these instructions. Start the Hello World program.

    Import program

    00001 #include "mbed.h"
    00002 
    00003 DigitalOut myled(LED1);
    00004 
    00005 int main() {
    00006     while(1) {
    00007         myled = 1;
    00008         wait(0.2);
    00009         myled = 0;
    00010         wait(0.2);
    00011     }
    00012 }
    
  2. Examine the documentation for DigitalOut class. Turn any LED on/off using class DigitalOut member function write. Explain the role of operator= in the class documentation. There is two ways to view documentation:
    1. Mbed Compiler, on the left side is placed directory tree, inside that tree you need to open folder with your program in it, that you named e.g. Introduction. This folder contains file main.cpp and mbed library (cog icon). There are three sub-libraries in the mbed library, you need to open the document named Classes and find the class whose documentation you want to study.
    2. on the following links you can find documentation for all the classes we will use in this course (and at CTM): old documentation that is still valid and contains examples and new documentation that also contains examples but also a more comprehensive description of the classes.
  3. Modify the Hello World program to flash other 3 LEDs (only one LED can flash).
  4. Modify the program to flash 2 or more LEDs at the same time (almost at the same time).
  5. Create a new program. Inside the newly created program, modify the program from previous task to flash the LED1 for 4 seconds, then turn off LED1 and flash LED2 for 4 seconds, turn off LED2 and go back to flash LED1 for 4 seconds etc. Use the while and for loops for this task.
  6. Declare and initialize two constant real variables T_TOTAL and T_FLASH, which will determine the total flash time of individual LEDs from the previous task, as well as the duration of each flash. E.g. instead of 4 seconds, set the total of 10 seconds for T_TOTAL and instead of default 0.2 seconds for T_FLASH, set the 0.5 seconds. The idea is to make a change only on those two places, and the rest of the code must carry out the task.
  7. Create a new program that contains one LED and the following blinking pattern:
    1. LED is turned on for 5 seconds, then it is turned off for 0.5 seconds.
    2. After that, the on time decreases to 4 seconds, with fixed off time (0.5 seconds).
    3. The pattern continues until the on time reaches 1 second, and after that the pattern starts from the beginning.
  8. Generalize the previous program to include the on time in a variable that can be set to an arbitrary integer value. The on time decrement remains the same (1 second).

Congratulations!

You have completed all the exercises in the Introduction topic. More interesting exercises are coming in the following topics!

Return to TVZ Mechatronics Team Homepage.


All wikipages