Tutorial: mbed - Part 2
Preparation
MCU board: Nucleo-F401RE
Refer to HUINS mbed experiment kit: Pin Map
GPIO Digital In/Out
We are going to create a simple program that turns LED(LD2) on and off by pressing the user button(BT1).
mbed class
Look up for DigitalOut and DigitalIn in mbed documentation for the fulll list of methods
Create a **** new program named as ‘TU_mbed_GPIO_LED_button’.
Write the following source code on ‘main.cpp’
Click on Compile button. Then, the binary files will be created and downloaded. Copy the binary file to MCU board via USB cable.
Push the reset button(black) and check the performance. The LED(LD2) should be turned on when the button is pressed.
External Interrupt
We are going to create a simple program that turns LED(LD2) on triggered by External Interrupt of user button(BT1).
mbed class
Create new program as ‘TU_mbed_ExtIn’.
Write the following code on ‘mbed’ complier.
We have created user defined functions of void pressed()
and void released()
.
Click on Compile button. Then, the binary files will be created and downloaded. Copy the binary file to MCU board via USB cable.
Whenever the user button(BT1) is pressed (at fall), then the LED should be ON. When the button is released then the LED should be off.
Exercise
The experiment kit has IR motion sensor(HD-SEN0018) that detects a motion of an object nearby. It is often used in automatic lighting system at the front door. It is connected to PinName D5
as DigitalIn
Use External interrupt to get the digital in data from the motion sensor
When the userbutton is pressed, it should turn-off the LED.
Hint:
Ticker (SysTick interrupt)
We are going to create a simple program that uses System Timer Tick Interrupt that occurs periodically. Lets turn LED on and off at 1 sec of period.
mbed class
Use the Ticker interface to set up a recurring interrupt; it calls a function repeatedly and at a specified rate.
Create new program as ‘TU_mbed_SysTick’.
tick.attach( )
makes periodic interrupt of second unit.
You can make LED blink every second, even though there is no infinite loop in main(). This is also called as the ‘ SysTIck interrupt’.
Click on Compile button. Then, the binary files will be created and downloaded. Copy the binary file to MCU board via USB cable.
LED(LD2) should blink every second.
Exercise
This experiment kit has a digital buzzer (MCKPI-G1410).
It is connected at DigitalOut PinName
PA_13
Buzz the sound for about 1second that repeats for every 3 seconds.
You can also may use wait(sec)
To use the buzzer, square digital signals such as
****
Last updated