This example shows how to configure LEDs to turn on and off and to dim and brighten using MATLAB® commands.
Connect an LED to pin 9 and GND on your Arduino® hardware.
Create an arduino object.
a = arduino;
Write data to the digital pin to turn the LED on and off repeatedly for 10 seconds.
for idx = 0:10 writeDigitalPin(a,'D9',1); pause(0.5); writeDigitalPin(a,'D9',0); pause(0.5); end
Change the brightness from maximum to minimum using the digital pin's PWM duty cycle.
for brightness = 1:-0.1:0 writePWMDutyCycle(a,'D9',brightness); pause(0.5); end
Once the connection is no longer needed, clear the arduino object.