#include <IRremote.h>
#include <MotorCar.h>
#include <Ultrasonic.h>
#include <myServo.h>
Ultrasonic ultrasonc(3,2);
MotorCar motor(4,5,8,12,10,11);
myServo servo;
int pos=0;
//int buzzerPin=1;
int ledPin=6;
//int ultInputPin=2;//echo
//int ultOutputPin=3;//trig
int time=0;//to calculate the rotation angle.
const int irReceiverPin=0;
IRrecv irrecv(irReceiverPin);
decode_results results;
//LED blinking
void ledBlink(const int interval=50)
{
digitalWrite(ledPin,HIGH);
delay(interval);
digitalWrite(ledPin,LOW);
delay(interval);
}
//define the IR code
#define ADV 0xFF18E7
#define LEF 0xFF10EF
#define BAC 0xFF4AB5
#define RIG 0xFF5AA5
#define STO 0xFF38C7
void setup()
{
Serial.begin(9600);
servo.ServoInit(9);//connect the signal Pin to control myServo.
motor.stopCar();
irrecv.enableIRIn();//start IR enable
}
void loop(){
servo.SetServoAngle(90);
int n=analogRead(A0)/6;
int distance=ultrasonc.Ranging(CM);
if(irrecv.decode(&results))
{
Serial.println(results.value,HEX);
switch(results.value)
{
case ADV:
motor.forward(100);
break;
case BAC:
motor.back(100);
break;
case LEF:
motor.turnLeft(100);
break;
case RIG:
motor.turnRight(100);
break;
case STO:
motor.stopCar();
break;
default:
delay(600);
}
irrecv.resume();
}
}
为什么我的程序执行的时候没有反应呢? 谁帮忙看看。 |