colorLeds[i].off()
Category:Circuit
Turns the specified colorLED off.
This method works just like led.off()
and will turn whichever LED is specified off. You can turn the colorLED back on with colorLeds[i].on()
.
Examples
Alternating Lights
onBoardEvent(buttonL, "down", function(event) {
colorLeds[0].off();
colorLeds[1].on();
colorLeds[2].off();
colorLeds[3].on();
colorLeds[4].off();
colorLeds[5].on();
colorLeds[6].off();
colorLeds[7].on();
colorLeds[8].off();
colorLeds[9].on();
});
onBoardEvent(buttonR, "down", function(event) {
colorLeds[0].on();
colorLeds[1].off();
colorLeds[2].on();
colorLeds[3].off();
colorLeds[4].on();
colorLeds[5].off();
colorLeds[6].on();
colorLeds[7].off();
colorLeds[8].on();
colorLeds[9].off();
});
Alternating Lights with For Loops
Does the same thing as the previous Alternating Lights example, but this time uses for loops.
onBoardEvent(buttonL, "down", function(event) {
for (var i = 0; i < 10; i = i+2){
colorLeds[i].off();
}
for (var i = 1; i < 10; i = i+2){
colorLeds[i].on();
}
});
onBoardEvent(buttonR, "down", function(event) {
for (var i = 0; i < 10; i = i+2){
colorLeds[i].on();
}
for (var i = 1; i < 10; i = i+2){
colorLeds[i].off();
}
});
onBoardEvent("buttonL", "press", function(event) {
colorLeds[8].off();
colorLeds[9].off();
});
Syntax
colorLeds[index].off()
Found a bug in the documentation? Let us know at support@code.org.