Page 110 - ARM Based Microcontroller Projects Using MBED
P. 110
96 7. USING THE Mbed WITH SIMPLE PROJECTS
/****************************************************************************
ROTATING LEDs
=============
In this project 8 LEDs are connected to PORT C pins of the Nucleo-F411RE
development board. The program Turns ON/OFF the LEDs in a rotating manner
such that only one LED is ON at any time 1 second delay is inserted between
each output.
Author: Dogan Ibrahim
Date : August 2018
File : LED8
******************************************************************************/
#include "mbed.h"
DigitalOut LEDS[] = {(PC_0),(PC_1),(PC_2),(PC_3),(PC_4),(PC_5),(PC_6),(PC_7)};
int main()
{
int k;
while(1)
{
for(k = 0; k <= 7; k++) // Do 8 times
{
LEDS[k] = 1; // LED ON
wait(1.0); // WAit 1 second
LEDS[k] = 0; // LED OFF
wait(1.0); // WAit 1 second
}
}
}
FIG. 7.29 Program listing.
modified program listing (program: LED8-2) shown in Fig. 7.30, the second parameter of
PortOut is set to 0x00FF so that all 8 lower byte of PORT C are used in the program. Array
State defines the values to be sent to the port so that the required LEDs are turned ON.
The program runs indefinitely inside a while loop. A for statement is used to extract bits from
array State and send these to the port. In this modified version of the program the delay is set
to 250ms.
7.7.9 Another Modified Program
The program given in this project can be modified by using the BusOut statement as shown
in Fig. 7.31 (program: LED8-3). The BusOut statement is used to create a group of GPIO pins
which can be addressed by a single value. In Fig. 7.31, PORT C pins are grouped as an 8-bit
port called LEDS. This port is then accessed by sending a value to it (e.g., LEDS¼1 turns ON
the first LED in the port group). 0.5s delay is inserted between each output.