Compare commits
No commits in common. "54822199754260cf81cd317550b6200d03e1c4a8" and "3aef5c642d707d56281095685ff96320e5cc265e" have entirely different histories.
5482219975
...
3aef5c642d
23
index.html
23
index.html
@ -9,32 +9,19 @@
|
|||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body class="stackedit">
|
<body class="stackedit">
|
||||||
<div class="stackedit__html">
|
<div class="stackedit__html"><h1 id="значение-ножки-сейчас--">Значение ножки сейчас - <span id="wertyui"></span></h1>
|
||||||
<h1 id="значение-ножки-сейчас--">Значение потенциометра сейчас - <span id="1"></span></h1>
|
|
||||||
<h1 id="значение-ножки-сейчас--">Значение ножки сейчас - <span id="2"></span></h1>
|
|
||||||
</div>
|
</div>
|
||||||
<script>
|
<script>
|
||||||
setInterval(()=>{
|
setInterval(()=>
|
||||||
fetch('/potentiometer')
|
fetch('/pin')
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
return response.json();
|
return response.json();
|
||||||
})
|
})
|
||||||
|
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
document.getElementById("1").innerHTML = data;
|
document.getElementById("wertyui").innerHTML = data;
|
||||||
|
|
||||||
})
|
})
|
||||||
|
, 2000);
|
||||||
fetch('/gpu')
|
|
||||||
.then((response) => {
|
|
||||||
return response.json();
|
|
||||||
})
|
|
||||||
|
|
||||||
.then((data) => {
|
|
||||||
document.getElementById("2").innerHTML = data;
|
|
||||||
|
|
||||||
})
|
|
||||||
} , 200);
|
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
27
index.js
27
index.js
@ -23,26 +23,18 @@ const {
|
|||||||
} = require('@serialport/parser-readline')
|
} = require('@serialport/parser-readline')
|
||||||
|
|
||||||
const port = new SerialPort({
|
const port = new SerialPort({
|
||||||
path: '/com11',
|
path: '/com9',
|
||||||
baudRate: 9600
|
baudRate: 9600
|
||||||
})
|
})
|
||||||
|
|
||||||
var str = "";
|
var str = "";
|
||||||
var obj;
|
|
||||||
|
|
||||||
const parser = port.pipe(new ReadlineParser({
|
const parser = port.pipe(new ReadlineParser({
|
||||||
delimiter: '\r\n'
|
delimiter: '\r\n'
|
||||||
}))
|
}))
|
||||||
parser.on('data', (data) => {
|
parser.on('data', (data) => {
|
||||||
if (str != data) {
|
if (str != data) {
|
||||||
try {
|
console.log(data);
|
||||||
obj = JSON.parse(data);
|
|
||||||
|
|
||||||
console.log(obj);
|
|
||||||
} catch {
|
|
||||||
console.log("Ошибка");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
str = data;
|
str = data;
|
||||||
})
|
})
|
||||||
@ -50,7 +42,6 @@ parser.on('data', (data) => {
|
|||||||
|
|
||||||
// Create a local server to receive data from
|
// Create a local server to receive data from
|
||||||
const server = http.createServer((req, res) => {
|
const server = http.createServer((req, res) => {
|
||||||
|
|
||||||
console.log(req.url);
|
console.log(req.url);
|
||||||
if (req.url == '/') {
|
if (req.url == '/') {
|
||||||
fs.readFile('index.html', (err, data) => {
|
fs.readFile('index.html', (err, data) => {
|
||||||
@ -71,20 +62,6 @@ const server = http.createServer((req, res) => {
|
|||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
});
|
});
|
||||||
res.end(str);
|
res.end(str);
|
||||||
} else if (req.url == '/potentiometer') {
|
|
||||||
res.writeHead(200, {
|
|
||||||
'Content-Type': 'application/json'
|
|
||||||
});
|
|
||||||
if (obj) {
|
|
||||||
res.end(obj.valuePotentiometer.toString());
|
|
||||||
}
|
|
||||||
} else if (req.url == '/gpu') {
|
|
||||||
res.writeHead(200, {
|
|
||||||
'Content-Type': 'application/json'
|
|
||||||
});
|
|
||||||
if (obj) {
|
|
||||||
res.end(obj.valueGPU.toString());
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
res.writeHead(404, "Not Found");
|
res.writeHead(404, "Not Found");
|
||||||
res.end();
|
res.end();
|
||||||
|
@ -1,32 +1,16 @@
|
|||||||
#include <Servo.h>
|
|
||||||
|
|
||||||
// Пин для сервопривода
|
#define PIN_INPUT 7 //вход7
|
||||||
int servoPin = 3;
|
|
||||||
// Создаем объект
|
|
||||||
Servo Servo1;
|
|
||||||
|
|
||||||
void setup (){
|
void setup (){
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
pinMode(A0, INPUT); // к входу A0 подключаем потенциометр
|
pinMode(PIN_INPUT, INPUT); //задаём вход
|
||||||
pinMode(A1, INPUT); // к входу A1 подключаем gpu
|
|
||||||
Servo1.attach(servoPin);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop (){
|
void loop (){
|
||||||
int valuePotentiometer = analogRead(A0); // считываем данные с порта A0
|
if(digitalRead(PIN_INPUT) == HIGH) {
|
||||||
int valueGPU = digitalRead(A1);
|
Serial.println("1");
|
||||||
char varJson[64];
|
} else {
|
||||||
sprintf(varJson, "{\"valuePotentiometer\": %d, \"valueGPU\": %d}", valuePotentiometer, valueGPU);
|
Serial.println("0");
|
||||||
Serial.println(varJson);
|
}
|
||||||
|
}
|
||||||
Servo1.write(valuePotentiometer / 12);
|
|
||||||
// // 0 градусов
|
|
||||||
// Servo1.write(0);
|
|
||||||
// delay(1000);
|
|
||||||
// // 90 градусов
|
|
||||||
// Servo1.write(90);
|
|
||||||
// delay(1000);
|
|
||||||
// // 180 градусов
|
|
||||||
// Servo1.write(180);
|
|
||||||
// delay(1000);
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user