Kaluma
Search…
LED
The led module supports LED which connect to GPIO pins. Use require('led') to access this module.

Class: LED

An instances of LED represents a LED.

new LED(pin)

  • pin <number> Pin number where LED connected.
1
// Create the LED instance
2
const {LED} = require('led');
3
const led = new LED(0); // LED connected to pin 0.
Copied!

on()

Turns on the LED.
1
// Turn on the LED.
2
const {LED} = require('led');
3
const led = new LED(0); // LED connected to pin 0.
4
led.on();
Copied!

off()

Turns off the LED.
1
// Turn off the LED.
2
const {LED} = require('led');
3
const led = new LED(0); // LED connected to pin 0.
4
led.off();
Copied!

toggle()

This method toggles the LED.
1
// Toggle the LED.
2
const {LED} = require('led');
3
const led = new LED(0); // LED connected to pin 0.
4
led.on();
5
delay(1000); // wait for 1sec
6
led.off();
7
delay(1000); // wait for 1sec
8
led.toggle(); // on
9
delay(1000); // wait for 1sec
10
led.toggle(); // off
Copied!

read()

  • Returns: <number> State of the LED. 1 means LED ON and 0 means LED OFF state.
Read the state of the LED.
1
// Read the state of LED.
2
const {LED} = require('led');
3
const led = new LED(0); // LED connected to pin 0.
4
led.on();
5
console.log(led.read()); // Returns 1.
6
delay(1000);
7
led.off();
8
console.log(led.read()); // Returns 0.
Copied!

pin

  • <number>
Pin number of the LED.
1
// Javascript example: Print out the LED pin number.
2
const {LED} = require('led');
3
const led = new LED(0); // LED connected to pin 0.
4
console.log (led.pin); // print out the LED pin number, 0;
Copied!
Last modified 7mo ago