<< ANALOG_READ_SB Arduino toolbox ARDUINO_SETUP >>

Arduino toolbox >> Arduino toolbox > ANALOG_WRITE_SB

ANALOG_WRITE_SB

Sends a PWM (Pulse Width Modulation value to a GPIO pin

Overview

Contents

Palette

Arduino

Description

The analog outputs on the Arduino Uno are available on pins 3,5,6,9 and 11. On the Arduino Mega these are the pins 1 to 13 and 44 to 46. Talking about "analog" outputs is however misleading: In fact the pins are digital pins to which however a pulses of a certain frequency are sent. The pulse width determines the amount of current sent to the pin (therefore "pulse width modulation").

The duty cycle can range from 0 (pin is always low) to 1 (pin is always high) which is mapped to an 8 bit value and therefore 0 to 255.

The maximum frequency for this block is approximately 125 Hz.

Parameters

The port number must be 3, 5, 6, 9, 10, 11 for an Arduino UNO (ports with the PWM symbol) and must be 1 to 13 or 44 to 46 for the Arduino MEGA.

Arduino card number must be 1 for the moment

Example 1

The example below shows the block use in case of a light dimmer on an LED in conjunction with a potentiometer. An LED is connected to port 10 on one end and over a resistor to ground on the other. The potentiometer is connected to analog input pin 2. Since the ADC dlivers a 10 bit value we need an attenuator by a factor of 4 before sending the value to the PWM pin.

See also


Report an issue
<< ANALOG_READ_SB Arduino toolbox ARDUINO_SETUP >>