Skip to content

Commit e65a456

Browse files
committed
Renamed ino file
2 parents 180db61 + 806dc28 commit e65a456

File tree

4 files changed

+56
-20
lines changed

4 files changed

+56
-20
lines changed

README.md

+18-6
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ Create an HTML file called `index.html`. Add the following code:
1818
var socket = io();
1919

2020
socket.on('data', function(data) {
21-
console.log(data);
22-
document.getElementById('sample').style.opacity = data/100+"%";
21+
console.log(data);
22+
document.getElementById('sample').style.opacity = data+"%";
2323
});
2424

2525
</script>
@@ -57,8 +57,20 @@ ls /dev/{tty,cu}.*
5757
On a PC you can use the command line and the following command:
5858

5959
```
60+
chgport
61+
```
62+
63+
On my PC when I use the `chgport` command I get the following output:
6064

6165
```
66+
AUX = \DosDevices\COM1
67+
COM1 = \Device\Serial0
68+
COM3 = \Device\Serial2
69+
```
70+
71+
In my Node.js I would use `COM3` as my serialport string.
72+
73+
If you're not sure which one is your Arduino, just disconnet your Arduino and execute the cpommand again and take note of which port is no longer on the list.
6274

6375
Or you can find the name in [Arduino Create](https://create.arduino.cc/editor) in the drop down menu used to select your Arduino.
6476

@@ -151,10 +163,10 @@ You will need to setup the following circuit using your Arduino:
151163

152164
## Launch Application
153165

154-
1. Using the Terminal start your Node.js app using `node app.js`.
155-
2. Open up a browser and enter the URL `http://localhost:3000/`.
156-
3. Using [Arduino Create](https://create.arduino.cc/editor) upload the sketch to your Arduino.
157-
4. Turn the dial on the Arduino device and watch the red square in the browser.t.
166+
1. Using [Arduino Create](https://create.arduino.cc/editor) upload the sketch to your Arduino.
167+
2. Using the Terminal start your Node.js app using `node app.js`.
168+
3. Open up a browser and enter the URL `http://localhost:3000/`.
169+
4. Turn the dial on the Arduino device and watch the red square in the browser.
158170

159171
## Tutorial Requirements:
160172

arduino-to-node.ino

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
int percent = 0;
2+
int prevPercent = 0;
3+
4+
void setup() {
5+
6+
Serial.begin( 9600 );
7+
8+
}
9+
10+
void loop() {
11+
12+
percent = round(analogRead(0) / 1024.00 * 100);
13+
14+
if(percent != prevPercent) {
15+
16+
Serial.println(percent);
17+
prevPercent = percent;
18+
19+
}
20+
21+
delay(100);
22+
23+
}

arduino_to_node.ino

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
int percent = 0;int prevPercent = 0;void setup() { Serial.begin( 9600 ); }void loop() { percent = round(analogRead(0) / 1024.00 * 100); if(percent != prevPercent) { Serial.println(percent); prevPercent = percent; } delay(100); }

index.html

+14-14
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,6 @@
33
<head>
44

55
<script src='https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.4/socket.io.js'></script>
6-
7-
<script>
8-
9-
var socket = io();
10-
11-
socket.on('data', function(data) {
12-
13-
console.log(data);
14-
15-
document.getElementById('sample').style.opacity = data+"%";
16-
17-
});
18-
19-
</script>
206

217
<style>
228

@@ -35,5 +21,19 @@ <h1>Communicating from an Arduino to Node.js</h1>
3521

3622
<div id="sample"></div>
3723

24+
<script>
25+
26+
var socket = io();
27+
28+
socket.on('data', function(data) {
29+
30+
console.log(data);
31+
32+
document.getElementById('sample').style.opacity = data+"%";
33+
34+
});
35+
36+
</script>
37+
3838
</body>
3939
</html>

0 commit comments

Comments
 (0)