|
昨晚成功用arduino红外发射模块给乐高红外接收器发送指令,带动乐高马达,so easy!
红外发射模块三根线分别接arduino的gnd、5v、数字口13,一块9v电池接LEGO 8884红外接收器,乐高8883马达按在红外接收器上,
LEGOPowerFunctions库文件复制到arduino安装目录下libraries\LEGOPowerFunctions子目录,运行以下测试代码:
- #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;
- }
- }
- }
复制代码
应该也能用在ev3的红外传感器上,红外信标功能如何实现还需要研究一下。。。。。。
|
|