writeLED
Turn LED on or off
Syntax
Description
Examples
You can locate and control the on-board LED, turning it on and off.
Create a connection from the MATLAB® software to the Raspberry Pi® board.
mypi = raspi
mypi =
Raspi with Properties:
DeviceAddress: 'raspberrypi-hysdu8X38o'
Port: 18725
BoardName: 'Raspberry Pi Model B Rev 2'
AvailableLEDs: {'led0'}
AvailableDigitalPins: [4 14 15 17 18 22 23 24 25 27 30 31]
AvailableSPIChannels: {}
AvailableI2CBuses: {'i2c-0' 'i2c-1'}
I2CBusSpeed: 100000
Supported peripheralsThe AvailableLEDs property shows the name
of the user-controllable LED.
Show the location of the user-controllable LED on the board.
showLEDs(mypi)

Turn on the specified LED by setting its value to 1 or true.
writeLED(mypi,'led0',1)Turn off the LED by setting its value to 0 or false.
writeLED(mypi,'led0',false)Restarting the Raspberry Pi hardware returns the LED to its previous function as an activity indicator.
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(mypi, 23) if buttonPressed for jj = 1:10 writeLED(mypi,'led0',1) pause(0.05) writeLED(mypi,'led0',0) pause(0.05) end end pause(0.1) end
Input Arguments
Extended Capabilities
You can deploy
writeLEDon the Raspberry Pi hardware in MATLAB Online™.To generate C/C++ code for this function, you must have an Embedded Coder license. For more information on selecting the right product stack according to your development goals, see Product Stack for Raspberry Pi Blockset.
Version History
Introduced in R2015b
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Sélectionner un site web
Choisissez un site web pour accéder au contenu traduit dans votre langue (lorsqu'il est disponible) et voir les événements et les offres locales. D’après votre position, nous vous recommandons de sélectionner la région suivante : .
Vous pouvez également sélectionner un site web dans la liste suivante :
Comment optimiser les performances du site
Pour optimiser les performances du site, sélectionnez la région Chine (en chinois ou en anglais). Les sites de MathWorks pour les autres pays ne sont pas optimisés pour les visites provenant de votre région.
Amériques
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)