-
Notifications
You must be signed in to change notification settings - Fork 0
/
hacklab-ArduinoComic-Page-14.html
68 lines (68 loc) · 2.15 KB
/
hacklab-ArduinoComic-Page-14.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-type"/>
<meta content="en-us" http-equiv="Content-Language"/>
<title>
/hacklab-ArduinoComic-Page-14
</title>
</head>
<body>
PAGE 14: Analog output
<br/>
Panel 53:
<br/>
Drawing: breadboard attached to Arduino with pot, LED and resistors
<br/>
(In text panel): Let’s use the changing values we receive from the pot as a dimmer to control an LED. Attach the anode through a resistor to the board at pin 3, cathode to ground.
<br/>
<br/>
Panel 54:
<br/>
Drawing: Diagram of pulse width modulation duty cycles on white shape.
<br/>
Labels:
<br/>
0% Duty Cycle - analogWrite(0)
<br/>
50% Duty Cycle - analogWrite(127)
<br/>
100% Duty Cycle - analogWrite(255)
<br/>
(In text panel): We’ll use Pulse Width Modulation (PWM). This is a method of simulating an analog value by manipulating the voltage, turning it on and off at different rates, or duty cycles. You can use PWM with pins 3, 5, 6, 9, 10, and 11.
<br/>
<br/>
Panel 55:
<br/>
Drawing: code for analog read analog write on white shape
<br/>
int sensorValue = 0;
<br/>
<br/>
void setup() {
<br/>
pinMode(3,OUTPUT);
<br/>
}
<br/>
<br/>
void loop() {
<br/>
sensorValue = analogRead(A0);
<br/>
analogWrite(3, sensorValue/4);
<br/>
}
<br/>
(In text panel): First we create a variable to store the value of the pot. In setup we make pin 3 an output. In loop, we store the value we have read from pin a0 in our variable. Then we write the value to pin 3, our LED pin. We have to divide the variable by 4, so we will have a range of values from 0 to 255, or a byte.
<br/>
<br/>
Panel 56:
<br/>
Drawing: On left, split panels- top: LED shines dimly, bottom: LED shines brightly. Right side: hand turns potentiometer.
<br/>
(In text panel): The brightness of the LED changes, ranging from completely off to very bright as you turn the pot.
<br/>
<br/>
</body>
</html>