led

Category:Circuit Playground

red led The led is an object representing the red LED next to the USB port. Internally this LED is connected to pin 13 of the Circuit Playground.

Properties and Methods

Examples

On and Off: Lightswitch

The red LED light turns on when the switch is flipped open, and off when the switch is flipped closed.

//The red LED light turns on when the switch is flipped open, and off when the switch is flipped closed.
onBoardEvent("toggleSwitch", "open", function(event) {
  led.on();
});
onBoardEvent("toggleSwitch", "closed", function(event) {
  led.off();
});

Blink: Blink Buttons

Changes the rate of how fast the button blinks depending on which button is pressed.

//Changes the rate of how fast the button blinks depending on which button is pressed.
var blinkRate = 50;

onBoardEvent(buttonL, "down", function(event) {
  blinkRate = blinkRate - 10;
  led.blink(blinkRate);
});

onBoardEvent(buttonR, "down", function(event) {
  blinkRate = blinkRate + 10;
  led.blink(blinkRate);
});

Pulse: Pulse versus Blink

onBoardEvent(toggleSwitch, "close", function(event) {
  led.pulse(200);
});
onBoardEvent(toggleSwitch, "open", function(event) {
  led.blink(200);
});

Toggle: Button Lightswitch

onBoardEvent(buttonL, "down", function(event) {
  led.toggle();
});

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