Compare commits

..

3 Commits

3 changed files with 37 additions and 14 deletions

View File

@ -1,7 +1,4 @@
// const { SerialPort } = require('serialport')
// // Create a port
// const port = new SerialPort({
// path: '/com16/tty-usbserial1',
@ -16,9 +13,28 @@
// port.on('data', function (data) {
// console.log('Data:', data.toString('UTF8'))
// })
const http = require('node:http');
const { SerialPort } = require('serialport')
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' }))
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);

View File

@ -1,9 +0,0 @@
int clockPin = 3; // Пин, соединённый с ножкой Clock
int resetPin = 2; // Пин, соединённый с ножкой Reset
void setup (){
Serial.begin(9600);
}
void loop (){
Serial.println("Привет!");
delay(1000);
}

View 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");
}
}