User Tools

Site Tools


arduino:analog_io:analogwrite

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

arduino:analog_io:analogwrite [2013/02/15 18:10]
127.0.0.1 external edit
arduino:analog_io:analogwrite [2024/02/16 01:04] (current)
Line 2: Line 2:
  
 ====Description   ==== ====Description   ====
-Writes an analog value ([[Tutorial/PWM  | PWM wave]]) to a pin.  Can be used to light a LED at varying brightnesses or drive a motor at various speeds.  After a call to **analogWrite()**, the pin will generate a steady square wave of the specified duty cycle until the next call to **analogWrite()** (or a call to **digitalRead()** or **digitalWrite()** on the same pin).  The frequency of the PWM signal is approximately 490 Hz.+Writes an analog value ( PWM wave) to a pin.  Can be used to light a LED at varying brightnesses or drive a motor at various speeds.  After a call to **analogWrite()**, the pin will generate a steady square wave of the specified duty cycle until the next call to **analogWrite()** (or a call to **digitalRead()** or **digitalWrite()** on the same pin).  The frequency of the PWM signal is approximately 490 Hz.
    
 On most Arduino boards (those with the ATmega168 or ATmega328), this function works on pins 3, 5, 6, 9, 10, and 11.  On the Arduino Mega, it works on pins 2 through 13.  Older Arduino boards with an ATmega8 only support analogWrite() on pins 9, 10, and 11.  On most Arduino boards (those with the ATmega168 or ATmega328), this function works on pins 3, 5, 6, 9, 10, and 11.  On the Arduino Mega, it works on pins 2 through 13.  Older Arduino boards with an ATmega8 only support analogWrite() on pins 9, 10, and 11. 
Line 32: Line 32:
 Sets the output to the LED proportional to the value read from the potentiometer. Sets the output to the LED proportional to the value read from the potentiometer.
  
- (:source lang=arduino:)+<code arduino>
 int ledPin = 9;      // LED connected to digital pin 9 int ledPin = 9;      // LED connected to digital pin 9
 int analogPin = 3;   // potentiometer connected to analog pin 3 int analogPin = 3;   // potentiometer connected to analog pin 3
Line 47: Line 47:
   analogWrite(ledPin, val / 4);  // analogRead values go from 0 to 1023, analogWrite values from 0 to 255   analogWrite(ledPin, val / 4);  // analogRead values go from 0 to 1023, analogWrite values from 0 to 255
 } }
-(:sourceend:)+</code>
  
  
  
 ====See also   ==== ====See also   ====
-* [[arduino:analog io:AnalogRead]]() +* [[arduino:analog io:AnalogRead]] 
-* [[arduino:analog io:AnalogWriteResolution]]() +* [[arduino:analog io:AnalogWriteResolution]]
-* [[Tutorial/PWM | Tutorial: PWM]]+
  
  
 Source: arduino.cc Source: arduino.cc
  

on the occasion of the current invasion of Russia in Ukraine

Russian Stop this War
arduino/analog_io/analogwrite.1360948235.txt · Last modified: 2024/02/16 01:02 (external edit)

Impressum Datenschutz