Paso 6: Programación de Arduino
#include < IRremote.h >
int rightforward = 8, rightbackward = 7, leftforward = 10, leftbackward = 9;
int RECV_PIN = 4, decodificar;
Irrecv(RECV_PIN) de IRrecv;
resultados de la decode_results;
void setup()
{
pinMode(leftforward,OUTPUT); pinMode(leftbackward,OUTPUT);
pinMode(rightforward,OUTPUT); pinMode(rightbackward,OUTPUT);
irrecv.enableIRIn();
}
void loop()
{
Si (irrecv.decode (y resultados))
{
Decode=Results.Value;
Serial.println(Decode);
Switch(Decode)
{
caso-10201: moveforward(); rotura;
caso-4081: movebackward(); rotura;
12495 del caso: moveleft(); rotura;
caso 28815: moveright(); rotura;
caso-20401: stop();
}
Delay(500);
irrecv.resume();
}
}
void moveforward()
{
digitalWrite(leftforward,HIGH);
digitalWrite(rightforward,HIGH);
digitalWrite(leftbackward,LOW);
digitalWrite(rightbackward,LOW);
}
void movebackward()
{
digitalWrite(leftforward,LOW);
digitalWrite(rightforward,LOW);
digitalWrite(leftbackward,HIGH);
digitalWrite(rightbackward,HIGH);
}
void moveleft()
{
digitalWrite(leftforward,LOW);
digitalWrite(rightforward,HIGH);
digitalWrite(leftbackward,LOW);
digitalWrite(rightbackward,LOW);
}
void moveright()
{
digitalWrite(leftforward,HIGH);
digitalWrite(rightforward,LOW);
digitalWrite(leftbackward,LOW);
digitalWrite(rightbackward,LOW);
}
void stopnow()
{
digitalWrite(leftforward,LOW);
digitalWrite(rightforward,LOW);
digitalWrite(leftbackward,LOW);
digitalWrite(rightbackward,LOW);
}
Desde aquí puede descargar archivos de la biblioteca de IRremote .