led.toggle()

Category:Circuit

Alternates from turning the red LED on and off

Changes based on the current state of the LED. If the LED is on when you use led.toggle(), then it will turn off after being called.

Examples

Extreme Toggle

onBoardEvent(lightSensor,"data", function(event) {
  led.toggle();
});

Toggle by 3's

Every third time you press the left button, toggle!

var buttonPress = 1;

onBoardEvent(buttonL,"down", function(event) {
  if (buttonPress >= 3){
    led.toggle();
    buttonPress = 1;
  } else {
    buttonPress = buttonPress + 1;
  }
});

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

Syntax

led.toggle()

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