Example — [Arduino] Create an LED Extension (Using the Default Arduino Template)

This page describes how to create an LED block to control an LED connected to Arduino Uno, using an LED module of the Seeed Studio Grove Starter Kit as an example. You can also use an LED module of another electronic kit.

Default Arduino template vs. universal template

For creating an LED control block for Arduino Uno, you can also refer to the example that uses the universal template in the "[Arduino] Create an LED Extension (Using the Universal Template)." Comparing these two examples, you will understand the advantages of the default Arduino template in creating Arduino extensions.

1. Create an extension by using the default Arduino template

Choose My Plugin > My Extension, click Add extension, select the default Arduino template in the dialog box that appears, and click OK.


Enter a name for the extension to be created and click OK.

2. Configure the extension

Configure the first block in the first block category for the extension.

(1) Set Content for the block.

Press space+@ to configure dropdown parameters as follows, so that we can select a port and LED state from drop-down list boxes.

(2) Configure the dropdown parameters.

Configure the first dropdown parameter.

Set Parameter name, Default value, and value options. An LED module of the the Seeed Studio Grove Starter Kit can connect to any of the ports D1 to D8.

Note: Click + to set value options in batches.

Configure the second dropdown parameter to LED status.

3. Configure the upload trancoding

Configure the following items in the Upload transcode area:

  • declare: The code set here appears before that set in setup() and is used to declare a variable.
  • setup: The code set here is embedded in the setup() function of Arduino ONCE.
  • code: The code set here appears in the position where the block is used.
  • _loop: The code set here is embedded in the _loop() function of Arduino ONCE.

The following Arduino code example is provided in the documentation for the Seeed Studio Grove Starter Kit:

void setup() {
  // initialize digital pin2  as an output.
  pinMode(2, OUTPUT);
// the loop function runs over and over again forever
void loop() {
  digitalWrite(2, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(2, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second

According to the preceding code, the following configuration is required:

  • Set pinMode in setup.
  • Set digitalWrite in code.
  • Use /*{port}*/ and /*status*/ to indicate the value of the dropdown parameters.

Click Save.

Now you can download the extension and drag it to your mBlock 5 PC client to test the block you have created!

Was this article helpful?
0 out of 0 found this helpful



Please sign in to leave a comment.