Compare commits
3 Commits
222e1c54ea
...
a37c3ba7f9
Author | SHA1 | Date | |
---|---|---|---|
a37c3ba7f9 | |||
7119c4a699 | |||
3fbcd57b63 |
26
index.js
26
index.js
@ -1,7 +1,4 @@
|
|||||||
// const { SerialPort } = require('serialport')
|
// const { SerialPort } = require('serialport')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// // Create a port
|
// // Create a port
|
||||||
// const port = new SerialPort({
|
// const port = new SerialPort({
|
||||||
// path: '/com16/tty-usbserial1',
|
// path: '/com16/tty-usbserial1',
|
||||||
@ -16,9 +13,28 @@
|
|||||||
// port.on('data', function (data) {
|
// port.on('data', function (data) {
|
||||||
// console.log('Data:', data.toString('UTF8'))
|
// console.log('Data:', data.toString('UTF8'))
|
||||||
// })
|
// })
|
||||||
|
|
||||||
|
const http = require('node:http');
|
||||||
const { SerialPort } = require('serialport')
|
const { SerialPort } = require('serialport')
|
||||||
const { ReadlineParser } = require('@serialport/parser-readline')
|
const { ReadlineParser } = require('@serialport/parser-readline')
|
||||||
const port = new SerialPort({ path: '/com16/ROBOT', baudRate: 9600 })
|
|
||||||
|
const port = new SerialPort({ path: '/com16', baudRate: 9600 })
|
||||||
|
|
||||||
|
var str = "";
|
||||||
|
|
||||||
const parser = port.pipe(new ReadlineParser({ delimiter: '\r\n' }))
|
const parser = port.pipe(new ReadlineParser({ delimiter: '\r\n' }))
|
||||||
parser.on('data', console.log)
|
parser.on('data', (data) => {
|
||||||
|
if (str != data) {
|
||||||
|
console.log(data);
|
||||||
|
}
|
||||||
|
str = data;
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
// Create a local server to receive data from
|
||||||
|
const server = http.createServer((req, res) => {
|
||||||
|
res.writeHead(200, { 'Content-Type': 'application/json' });
|
||||||
|
res.end(str);
|
||||||
|
});
|
||||||
|
|
||||||
|
server.listen(2048);
|
@ -1,9 +0,0 @@
|
|||||||
int clockPin = 3; // Пин, соединённый с ножкой Clock
|
|
||||||
int resetPin = 2; // Пин, соединённый с ножкой Reset
|
|
||||||
void setup (){
|
|
||||||
Serial.begin(9600);
|
|
||||||
}
|
|
||||||
void loop (){
|
|
||||||
Serial.println("Привет!");
|
|
||||||
delay(1000);
|
|
||||||
}
|
|
16
sketch_mar22a/sketch_mar22a.ino
Normal file
16
sketch_mar22a/sketch_mar22a.ino
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
|
||||||
|
#define PIN_INPUT 7 //вход7
|
||||||
|
|
||||||
|
|
||||||
|
void setup (){
|
||||||
|
Serial.begin(9600);
|
||||||
|
pinMode(PIN_INPUT, INPUT); //задаём вход
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop (){
|
||||||
|
if(digitalRead(PIN_INPUT) == HIGH) {
|
||||||
|
Serial.println("1");
|
||||||
|
} else {
|
||||||
|
Serial.println("0");
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user