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.

#define LED_B 2
#define LED_R 3

Then, set the pin directions as output.

pinMode(LED_B, OUTPUT)
pinMode(LED_R, OUTPUT)

Now, the LED configuration is ready.

Basic Members

Digital Write

Turns LEDs on or off.

digitalWrite(pin, value);
  • 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
// Define LED connections
#define LED_B 2
#define LED_R 3

void setup() {
  // Initialize LEDs
  pinMode(LED_B, OUTPUT);
  pinMode(LED_R, OUTPUT);
}

void loop() {
  // Turn on Blue LED
  digitalWrite(LED_B, HIGH);
  delay(500);

  // Turn on Red LED
  digitalWrite(LED_R, HIGH);
  delay(500);

  // Turn off Blue LED
  digitalWrite(LED_B, LOW);
  delay(500);

  // Turn off Red LED
  digitalWrite(LED_R, LOW);
  delay(500);
}

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 updated