Skip to content

树莓派上用nodejs 写的 l298n模块的驱动程序 依赖rpio库,后面又封装了一个基于pigpio的

Notifications You must be signed in to change notification settings

hujiangyi/l298n

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rpio-l298n

基于rpio实现的l298n的驱动.

安装

可以使用 npm安装

$ npm install rpio-l298n

用法

可以控制两个连接到L298N的电机。电机被编号为NO1和NO2.

使用模块的例子

const readline = require('readline');
const L298N = require('../l298n.js');

let l298n = new L298N(12,13,15,null,null,null);
l298n.setSpeed(l298n.NO1,20);

const rl = readline.createInterface({
	    input: process.stdin,
	    output: process.stdout
});
rl.on('line', function (input) {
    if (input === 'quit()') {
        rl.close();
    } else if (input === 'f') {
	    l298n.forward(l298n.NO1);
    } else if (input === 'b') {
	    l298n.backward(l298n.NO1)
    } else if (input === 't') {
	    l298n.stop(l298n.NO1);
    } else {
	    l298n.setSpeed(l298n.NO1,parseInt(input));
    }
});

process.on("SIGINT", function(){
    l298n.stop(l298n.NO1);
    console.log('shutdown!');
    process.exit(0);
});

设置转速

l298n.setSpeed(NUM(NO1\NO2), speed(0-100));

向前转动

l298n.forward(NUM(NO1\NO2));

向后转动

l298n.backward(NUM(NO1\NO2));

停止转动

l298n.stop(NUM(NO1\NO2));

About

树莓派上用nodejs 写的 l298n模块的驱动程序 依赖rpio库,后面又封装了一个基于pigpio的

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published