Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Table of Contents

Analog vs. Digital

  • Arduinos are digital devices – ON or OFF. Also called discrete

  • Analog signals are anything that can be a full range of values. Examples?

Digital Signal

Analog Signal

Image Removed
Image Added
Image Removed
Image Added
  • Arduino does not generate true analog outputs. The instantaneous output is always 0V or 5V.

  • How do we generate the effect of analog using digital?

Pulse Width Modulation (PWM)

  • To create (mimic) an analog signal, the Arduino uses a technique called Pulse Width Modulation (PWM). By varying the duty cycle, we can mimic an “average” analog voltage

...

analogWrite()

C++

Blocks

Using a variable val

Code Block
themeConfluence
analogWrite(pin, val);
]] ></ac:plain-text-body></ac:structured-macro></div></td><td><div class="content-wrapper"><p><ac:image ac:thumbnail="true" ac:width="250"><ri:attachment ri:filename="image2020-1-21_19-10-22.png" /></ac:image></p><p>Note : The example above shows pin 11 being used. We can't use a variable for pin number with Blocks</p></div></td></tr><tr><td colspan="1"><div class="content-wrapper">Using a constant (hard-coded) <em>val</em><ac:structured-macro ac:name="code" ac:schema-version="1" ac:macro-id="4000e7d5-af44-48c7-b887-ec5fc1416d61"><ac:parameter ac:name="theme">Confluence</ac:parameter><ac:plain-text-body><![CDATA[analogWrite(3, 128);]] ></ac:plain-text-body></ac:structured-macro></div></td><td colspan="1"><div class="content-wrapper"><p><ac:image ac:thumbnail="true" ac:width="230"><ri:attachment ri:filename="image2020-1-21_19-10-51.png" /></ac:image></p></div></td></tr></tbody></table><p><span style="color: rgb(0,0,0);">pin </span>&ndash; refers to the OUTPUT pin (limited to pins 3, 5, 6, 9, 10, 11.) &ndash; denoted by a ~ symbol</p><p>val &ndash; 8 bit value (0 &ndash; 255).&nbsp;</p><p>0 =&gt; 0V</p><p>255 =&gt; 5V&nbsp;</p><p><strong><ac:image ac:width="300"><ri:attachment ri:filename="image2019-7-31_17-14-47.png" /></ac:image></strong></p><h3>Screencast</h3><p><ac:structured-macro ac:name="widget" ac:schema-version="1" ac:macro-id="21a7dd65-21c5-4bfc-8203-2f48851a5916"><ac:parameter ac:name="url"><ri:url ri:value="http://youtube.com/watch?v=pysVJDASdsc" /></ac:parameter></ac:structured-macro></p><p><br /></p>
image2020-1-21_19-10-22.pngImage Added

Note : The example above shows pin 11 being used. We can't use a variable for pin number with Blocks

Using a constant (hard-coded) val

Code Block
analogWrite(3, 128);
image2020-1-21_19-10-51.pngImage Added

pin – refers to the OUTPUT pin (limited to pins 3, 5, 6, 9, 10, 11.) – denoted by a ~ symbol

val – 8 bit value (0 – 255). 

0 => 0V

255 => 5V 

...