Robofun 機器人論壇
標題:
Arduino紅外線遙控車
[打印本頁]
作者:
sunnyyea
時間:
2014-10-21 17:46
標題:
Arduino紅外線遙控車
求助!!
請問
我要如何把它改成遙控器按住按鈕時,車子走動,放開即停止
#include <IRremote.h>
int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
Serial.begin(9600);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
irrecv.enableIRIn(); // Start the receiver
}
void stop()
{
digitalWrite(3,LOW);
digitalWrite(4,HIGH);
digitalWrite(6,LOW);
digitalWrite(7,HIGH);
}
void loop() {
if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);
if(results.value==0x85AEFD19){//FORWARD
stop();
digitalWrite(3,HIGH);
digitalWrite(4,HIGH);
digitalWrite(6,HIGH);
digitalWrite(7,HIGH);
}
if(results.value==0xB66D73CD){//BACK
stop();
digitalWrite(3,HIGH);
digitalWrite(4,LOW);
digitalWrite(6,HIGH);
digitalWrite(7,LOW);
}
if(results.value==0x8F890759){//LEFT
stop();
digitalWrite(3,HIGH);
digitalWrite(4,LOW);
digitalWrite(6,HIGH);
digitalWrite(7,HIGH);
}
if(results.value==0x5C5C901D){//RIGHT
stop();
digitalWrite(3,HIGH);
digitalWrite(4,HIGH);
digitalWrite(6,HIGH);
digitalWrite(7,LOW);
}
}
irrecv.resume(); // Receive the next value
}
}
歡迎光臨 Robofun 機器人論壇 (https://robofun.net/forum/)
Powered by Discuz! X3.2