8356| 1
|
[进阶] DFR0095红外发射模块遥控乐高红外接收器和马达 |
昨晚成功用DFR0095红外发射模块给乐高红外接收器发送指令,带动乐高马达,so easy! DFR0095三根线分别接Arduino的gnd、5v、数字口13,一块9v电池接LEGO 8884红外接收器,乐高8883马达按在红外接收器上, LEGOPowerFunctions库文件复制到arduino安装目录下libraries\LEGOPowerFunctions子目录,运行以下测试代码: [mw_shl_code=applescript,true]/* example for the 8275 bulldozer */ #include <legopowerfunctions.h> // IR led on port 13 LEGOPowerFunctions lego(13); int timeout, count; void setup() { } void loop() { timeout = 5; // 5 secs count = 0; while(timeout > 0) { lego.ComboPWM(PWM_REV4, PWM_FWD4, CH1); // 50% speed delay(100); if (count++ == 10) { timeout--; count = 0; } } lego.ComboPWM(PWM_FLT, PWM_FLT, CH1); // stop delay(1000); timeout = 3; // 5 secs count = 0; while(timeout > 0) { lego.ComboMode(RED_FWD, BLUE_FWD, CH1); // turn delay(100); if (count++ == 10) { timeout--; count = 0; } } }[/mw_shl_code] 若配合手柄,可以实现许多功能。 |
© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed