-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassignment1.html
219 lines (198 loc) · 9.48 KB
/
assignment1.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, maximum-scale=1.0" />
<title>Assignment 1</title>
<link href="style/style.css" media="screen" rel="stylesheet" type="text/css" />
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Forum&family=Josefin+Sans:ital,wght@0,100;0,400;1,100;1,400&family=Raleway:ital,wght@0,600;1,600&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link rel="stylesheet" href="//cdn.jsdelivr.net/gh/highlightjs/[email protected]/build/styles/default.min.css">
<script src="//cdn.jsdelivr.net/gh/highlightjs/[email protected]/build/highlight.min.js"></script>
<script src="https://code.jquery.com/jquery-3.6.3.min.js" integrity="sha256-pvPw+upLPUjgMXY0G+8O0xUf+/Im1MZjXxxgOcBQBXU=" crossorigin="anonymous"></script>
<script src="script/index.js"></script>
<script src="script/lightbox.js"></script>
</head>
<body>
<nav>
<h4 class="top-title">HCDE 439</h4>
<div class="nav-list">
<a class="nav-items" href="index.html">Home</a>
<div class="dropdown" style="padding-top: 2px;">
<a href="#">Assignments</a>
<!-- Assignments -->
<!-- <div style="padding-top: 2px;">Assignments</div> -->
<div class="dropdown-content">
<a class="nav-items" href="assignment1.html">Assignment 1</a>
<a class="nav-items" href="assignment2.html">Assignment 2</a>
<a class="nav-items" href="assignment3.html">Assignment 3</a>
<a class="nav-items" href="assignment4.html">Assignment 4</a>
<a class="nav-items" href="assignment5.html">Assignment 5</a>
<a class="nav-items" href="assignment6.html">Assignment 6</a>
</div>
</div>
<a class="nav-items" href="final.html">Final Project</a>
</div>
</nav>
<div class="dark1">
<h2>Assignment 1 -- Blink</h2>
<p>
Basic Control of the Arduino and LEDs
</p>
</div>
<div class="content bright1" id="schematic">
<div class="title">
<h3>Schematic</h3>
<div class="subtitle">Treasure Maps</div>
</div>
<div class="lightbox-preview">
<img src="static/A1/A1_schem.svg" class="media" onclick='openLightbox("lightbox0");'>
</div>
<div class="lightbox-expand" onclick='closeLightbox("lightbox0");' id="lightbox0" style="display: none;">
<img src="static/A1/A1_schem.svg" class="media">
</div>
<div class="lightbox-preview">
<img src="static/A1/A1_bb.svg" class="media" onclick='openLightbox("lightbox1");'>
</div>
<div class="lightbox-expand" onclick='closeLightbox("lightbox1");' id="lightbox1" style="display: none;">
<img src="static/A1/A1_bb.svg" class="media">
</div>
<p>
The images above are my schematic for assignment 1. There are 3 LEDs, their positive nodes are connected to pin 13, 12, and 11 of the Arduino.
Their negative nodes are connected together and connected with a 330 ohm, 220 ohm, and 100 ohm resistors in series. Then the resistor is connected to the ground on the Arduino board.
</p>
<h4>Why 330, 220, and 100?</h4>
<p>
From data sheet we know that LED have a working current of 20mA. When Arduino's pins are acting as power, they provide 5V power.
From the equation <code>I = V / R</code>, we can calculate that a 250 ohm resistor is needed as a bare minimum. In order to limit the current and make the LEDs safer,
I added a 220 ohm, a 330 ohm, and a 100 ohm resistor to create a 650 ohm equivalent resistance.
</p>
</div>
<div class="content dark2" id="circuit">
<div class="title">
<h3>Circuit</h3>
<div class="subtitle">Above the blueprint</div>
</div>
<div class="lightbox-preview">
<img src="static/A1/PXL_20230114_040926875.jpg" class="media" onclick='openLightbox("lightbox2");'>
</div>
<div class="lightbox-expand" onclick='closeLightbox("lightbox2");' id="lightbox2" style="display: none;">
<img src="static/A1/PXL_20230114_040926875.jpg" class="media">
</div>
<p>
The above image shows the actual Arduino circuit build on breadboard.
</p>
</div>
<div class="content bright2" id="firmware">
<div class="title">
<h3>Firmware</h3>
<div class="subtitle">Inside the chips</div>
</div>
<div class="code-wrapper">
<pre><code class="arduino">bool led11 = false;
bool led12 = false;
bool led13 = false;
long prevMs[3];
char delimiter = ',';
int DEFAULT_DELAY = 1500;
int delayArr[4] = {DEFAULT_DELAY, DEFAULT_DELAY, DEFAULT_DELAY, DEFAULT_DELAY};
// Turn LED on or off based on the input delay, can blink while running other functions
// (int) ledPort - Port number that connect led port
// (int) delay - Milliseconds that
bool updateLed(int ledPort, int delay, bool ledState, int delayOn = 1000) {
long currMs = millis();
long interval = currMs - prevMs[13 - ledPort];
int delayComm = delayOn;
if (ledState) {
delayComm = delay;
}
if (interval >= delayComm) {
ledState = !ledState;
digitalWrite(ledPort, ledState);
prevMs[13 - ledPort] = currMs;
}
return ledState;
}
void setup() {
// Open serial communication with computer
Serial.begin(115200);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
}
void loop() {
// If there's any text send by the computer, enter the "if" condition
if (Serial.available() > 0) {
Serial.println("Serial Available");
// Access and store the received string
String inputStr = Serial.readString();
String token = inputStr;
// Ready to extract delay time from string
int inputDelay = DEFAULT_DELAY;
int i = 0;
// while there are still delay times to be extracted ("," presents)
while (inputStr.indexOf(delimiter) >= 0) {
// Extract from the start to the first ","
token = inputStr.substring(0, inputStr.indexOf(delimiter));
// Delete what's extracted and the ","
inputStr = inputStr.substring(inputStr.indexOf(delimiter) + 1);
// Delete any space
inputStr.trim();
// Convert to int
inputDelay = token.toInt();
Serial.println(token);
// Store delay time into array
delayArr[i] = inputDelay;
//iterate
i++;
delay(1000);
}
Serial.println(inputStr);
inputDelay = inputStr.toInt();
delayArr[i] = inputDelay;
}
// led 13 is always blinking at 1000ms
// led 12 and 11 blinks at 1000ms at first, when string is received, arduino parses the first four numbers
// and use them as led on & off delay
led13 = updateLed(13, DEFAULT_DELAY, led13, DEFAULT_DELAY);
led12 = updateLed(12, delayArr[0], led12, delayArr[1]);
led11 = updateLed(11, delayArr[2], led11, delayArr[3]);
}</code></pre>
</div>
</div>
<div class="content dark1" id="actual-operation">
<div class="title">
<h3>Actual Operation</h3>
<div class="subtitle">Coming alive</div>
</div>
<div class="lightbox-preview">
<img src="static/A1/ezgif-5-3b6e5db18b (1).gif" class="media" onclick='openLightbox("lightbox3");'></img>
</div>
<div class="lightbox-expand" id="lightbox3" onclick='closeLightbox("lightbox3");' style="display: none;">
<img src="static/A1/ezgif-5-3b6e5db18b (1).gif" class="media"></img>
</div>
<p>The above gif shows how this program run, when the user enters up to 4 numbers, <i>a1, a2, a3, a4</i>, the LEDs flash at different rates.
<ul>
<li>
LED 13 (top yellow LED) acts as a standard beacon, it always flashes at 1000 milliseconds
</li>
<li>
LED 12 (middle red LED) lights up for a1 milliseconds and remains dark for a2 milliseconds
</li>
<li>
LED 11 (lower yellow LED) lights up for a3 milliseconds and remains dark for a4 milliseconds
</li>
</ul>
</p>
</div>
<button onclick="scrollToTop()" id="topBtn" title="Go to top">
<span class="material-icons">
arrow_upward
</span>
</button>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/highlight.min.js"></script>
<script>hljs.highlightAll();</script>
</body>
</html>