Contenido principal

writePWMDutyCycle

R2026b

Generate PWM signal with specified duty cycle on digital pin

Description

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

writePWMDutyCycle(a, pin, dutyCycle) sets the PWM duty cycle on a digital pin specified for the Arduino® hardware a.

example

Examples

collapse all

Specify a 0.33 duty cycle for an LED attached to digital pin 5 on Arduino hardware.

a = arduino();
writePWMDutyCycle(a,'D5',0.33);

Input Arguments

collapse all

Arduino hardware connection created using arduino, specified as an object.

Digital pin number on the physical hardware, specified as a character vector.

Value of digital pin’s PWM duty cycle specified as number between 0 and 1.

The average voltage at the digital pin is the product of dutyCycle and VCC voltage of the Arduino board. The VCC can either be 3.3V or 5V.

More About

collapse all

Alternative Functionality

App

Use the Pin Explorer pane and Pin Configuration panel in the Arduino Explorer to write PWM signal with specified duty cycle on digital pin of Arduino or any other supported hardware in MATLAB and MATLAB Online™. In the Pin Explorer pane, click the row corresponding to the pin that you want to configure. The Pin Configuration panel displays the options you can use to configure the selected pin. In the Pin Configuration panel, set the Mode as PWM, set the PWM Mode as Duty Cycle, and if required specify a Label to uniquely identify the pin. For more information, see Configure Read and Write for GPIO Pins Using Arduino Explorer App.

Version History

Introduced in R2014b