Main Content

writePWMDutyCycle

Generate PWM signal with specified duty cycle on digital pin

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

Description

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.

More About

collapse all

Code Generation Using MATLAB Function Block

  • Use writePWMDutyCycle in a MATLAB® Function block with the Simulink® Support Package for Arduino Hardware to generate code that can be deployed on Arduino Hardware.

  • Configure the Arduino peripherals to the appropriate mode using configurePin before using writePWMDutyCycle in the MATLAB Function block.

Version History

Introduced in R2014b