createLed()

Category:Maker

A command to create a new LED object that can be programmed in the same way as the blocks in the Circuit drawer. The var myLed = createLed() command creates a new LED object named myLed that behaves just like the led blocks you've been using. Remember to pass in a pin parameter so the board knows where the LED is connected.

Examples

// Create a new LED object attached to pin 2
var myLed = createLed(2);

// turn myLed on
myLed.on();

var leftLED = createLed(3);
leftLED.blink(200);

var rightLED = createLed(10);
rightLED.blink(200);

Syntax

var myLed = createLed(pin);

Parameters

NameTypeRequired?Description
Pin number The number of the pin your LED is connected to. This is usually printed on your board, but can also be found in your board's documentation.

Returns

New LED object

Tips

  • You'll need to work in text mode to use this block. You can still drag out blocks that you're familiar with from the Circuit drawer, you'll just need to change the name of the object.
  • led.pulse() will not work with new LEDs.
  • You can create new LED objects on pins 0, 2, 3, 6, and 12.

Found a bug in the documentation? Let us know at documentation@code.org