Main Content

writeLED

Turn LED on or off

Add-On Required: This feature requires the MATLAB Support Package for BeagleBone Black Hardware add-on.

Description

example

writeLED(bbb,led,value) turns the selected LED on or off.

Examples

Control the Onboard LED

Locate and control the onboard LED, turning it on and off.

Create a connection from the MATLAB® software to the BeagleBone® Black hardware.

bbb = beaglebone
bbb = 

  beaglebone with properties:

           DeviceAddress: '192.168.7.2'
               BoardName: 'BeagleBone Black Rev 00C0'
           AvailableLEDs: {'USR0'  'USR1'  'USR2'  'USR3'}
    AvailableDigitalPins: {1x29 cell}
     AvailableAnalogPins: {'AIN0'  'AIN1'  'AIN2'  'AIN3'  'AIN4'  'AIN5'  'AIN6'}
        AvailablePWMPins: {}
    AvailableSPIChannels: {}
       AvailableI2CBuses: {'i2c-1'}
    AvailableSerialPorts: {}
        AvailableWebcams: {} 

The AvailableLEDs property shows the name of the user-controllable LED.

Show the location of the user-controllable LED on the board.

showLEDs(bbb)

The figure shows the output of a call to showLEDs.

Turn on the specified LED by setting its value to 1 or true.

writeLED(bbb,'usr0',1)

Turn off the LED by setting its value to 0 or false.

writeLED(bbb,'usr0',false)

Restarting the BeagleBone Black hardware returns the LED to its previous function as an activity indicator.

Flash the LED in Response to an Input

You can flash the LED in response to an input signal on one of the GPIO pins.

For example, you can use a button and a resistor in series to connect one of the +3.3 V outputs to GPIO 23. When you press the button, readDigitalPin reads the positive voltage, if buttonPressed becomes true, and the program flashes the LED 10 times.

for ii = 1:100
    buttonPressed = readDigitalPin(bbb, '23')
    if buttonPressed
        for jj = 1:10
            writeLED(bbb,'usr0',1)
            pause(0.05)
            writeLED(bbb,'usr0',0)
            pause(0.05)
        end
    end
    pause(0.1)
end

Input Arguments

collapse all

BeagleBone Black connection created using beaglebone, specified as an object.

LED name, specified as a character vector.

To get the name and location of user-controllable LEDs, use showLEDs.

Example: 'usr0'

Data Types: char

LED off or on, specified as a logical value.

Example: 0

Data Types: logical

Version History

Introduced in R2015a