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?
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 |
theme | Confluence]] ></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>– refers to the OUTPUT pin (limited to pins 3, 5, 6, 9, 10, 11.) – denoted by a ~ symbol</p><p>val – 8 bit value (0 – 255). </p><p>0 => 0V</p><p>255 => 5V </p><p><strong><ac:image ac:width="300"><ri:attachment ri:filename="image2019-7-31_17-14-47.png" /></ac:image></strong></p><p><br /></p><p><br /></p> | Image 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); |
| Image 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
...