很早就想做一个遥控车玩玩,还因此买了一块Arduino Mega 2560,结果由于种种原因,最终没有做成,
Arduino放在家里吃灰了。
开始接触Espruino之后,做个遥控车的想法又回来了,因为Espruino玩起来确实方便,这个用过的人应该
都知道哈~
买了一个遥控器模块,一个两驱的小车套件。代码很简单,但是确实实现了简单的遥控功能,至于避碍,
巡线啥滴[就以后再说吧~
接线方法请参考代码里的相关参数~
function up()
{
digitalWrite([C0,C1,C2,C3],0b1001);
}
function down()
{
digitalWrite([C0,C1,C2,C3],0b0110);
}
function left()
{
digitalWrite([C0,C1,C2,C3],0b1010);
}
function right()
{
digitalWrite([C0,C1,C2,C3],0b0101);
}
function stop()
{
digitalWrite([C0,C1,C2,C3],0b0000);
}
setWatch("right()",A2,{ repeat:true, edge:'rising' });
setWatch("stop()",A2,{ repeat:true, edge:'falling' });
setWatch("down()",A3,{ repeat:true, edge:'rising' });
setWatch("stop()",A3,{ repeat:true, edge:'falling' });
setWatch("up()",A4,{ repeat:true, edge:'rising' });
setWatch("stop()",A4,{ repeat:true, edge:'falling' });
setWatch("left()",A5,{ repeat:true, edge:'rising' });
setWatch("stop()",A5,{ repeat:true, edge:'falling' });
//setWatch(function(){},A6,{ repeat:true, edge:'rising' });
//setWatch(function(){},A6,{ repeat:true, edge:'falling' });
function onInit()
{
analogWrite(A0,1);
analogWrite(A1,1);
}
![](http://www.espruino.cn/wp-content/uploads/2021/07/161048moo93eox38jf334j.jpg)
![](http://www.espruino.cn/wp-content/uploads/2021/07/161048wwktuwow888xuxa7.jpg)