User LEDs
This documentation includes installation guidelines and sample code for your hardware.

Overall Info

There are two user LEDs available onboard.

LED Connections

    LED 1 (Blue): D2.
    LED 2 (Red): D3.

Arduino Library

There is no need to add a library to control LEDs. All you need to do is defining LED pin numbers, setting pin directions and controlling them.

Initialization

To initialize the LEDs, first define the connections.
1
#define LED_B 2
2
#define LED_R 3
Copied!
Then, set the pin directions as output.
1
pinMode(LED_B, OUTPUT)
2
pinMode(LED_R, OUTPUT)
Copied!
Now, the LED configuration is ready.

Basic Members

Digital Write

Turns LEDs on or off.
1
digitalWrite(pin, value);
Copied!
    Parameters
      Pin: LED pin.
      Value: LED state. "HIGH" or "LOW".
    Returns
      None

Examples

You can open the example from Arduino IDE > File > Examples > Examples from Custom Libraries > Turta MKR Sensor Shield > User LEDs. There is one example of this sensor.
This application demonstrates blinking of the LEDs.
To run the example:
    1.
    Open the LED Blink sketch from the examples menu.
    2.
    Select your Arduino MKR series board from the Tools > Board menu.
    3.
    Select your device's COM port from Tools > Port menu.
    4.
    Open Serial Monitor from Tools > Serial Monitor.
    5.
    Select 115.200 baud from the Serial Monitor's status bar.
    6.
    Upload the code to your device.
Sample Code
LED_Blink.ino
1
// Define LED connections
2
#define LED_B 2
3
#define LED_R 3
4
5
void setup() {
6
// Initialize LEDs
7
pinMode(LED_B, OUTPUT);
8
pinMode(LED_R, OUTPUT);
9
}
10
11
void loop() {
12
// Turn on Blue LED
13
digitalWrite(LED_B, HIGH);
14
delay(500);
15
16
// Turn on Red LED
17
digitalWrite(LED_R, HIGH);
18
delay(500);
19
20
// Turn off Blue LED
21
digitalWrite(LED_B, LOW);
22
delay(500);
23
24
// Turn off Red LED
25
digitalWrite(LED_R, LOW);
26
delay(500);
27
}
Copied!
Result
After the application is uploaded to the device, it turns the LEDs on and off continuously.
The application runs forever until you clear it from memory.
Last modified 2yr ago