sketch_nov04b.pde (2286Bytes)
#include <IRremote.h>
#define m1F 6
#define m1R 7
#define m2F 5
#define m2R 8
long F = 1979994096;
long L = 1979994056;
long R = 1979994048;
long B = 1979994076;
long S = 1979994080;
int RECV_PIN = 4;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
pinMode(13, OUTPUT);
pinMode(m1F, OUTPUT);
pinMode(m1R, OUTPUT);
pinMode(m2F, OUTPUT);
pinMode(m2R, OUTPUT);
Stop();
delay(500);
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
}
void loop()
{
if (irrecv.decode(&results))
{
Serial.println(results.value);
irrecv.resume(); // Receive the next value
}
if (results.value = F)
{
Forward();
}
else if (results.value != F)
{
Stop();
}
if (results.value = L)
{
Left();
}
else if (results.value != L)
{
Stop();
}
if (results.value = R)
{
Right();
}
else if (results.value != R)
{
Stop();
}
if (results.value = B)
{
Reverse();
}
else if (results.value != B)
{
Stop();
}
if (results.value = S)
{
Stop();
}
}
void Stop()
{
digitalWrite(m1F, LOW);
digitalWrite(m1R, LOW);
digitalWrite(m2F, LOW);
digitalWrite(m2R, LOW);
delay(500);
}
void Forward()
{
digitalWrite(m1F, HIGH);
digitalWrite(m1R, LOW);
digitalWrite(m2F, HIGH);
digitalWrite(m2R, LOW);
delay(500);
}
void Reverse()
{
digitalWrite(m1F, LOW);
digitalWrite(m1R, HIGH);
digitalWrite(m2F, LOW);
digitalWrite(m2R, HIGH);
delay(500);
}
void Right()
{
digitalWrite(m1F, LOW);
digitalWrite(m1R, HIGH);
digitalWrite(m2F, HIGH);
digitalWrite(m2R, LOW);
delay(500);
}
void Left()
{
digitalWrite(m1F, HIGH);
digitalWrite(m1R, LOW);
digitalWrite(m2F, LOW);
digitalWrite(m2R, HIGH);
delay(500);
}
//The problem is... I can't find out...
UPDATE :
Ok...i've fixed the code using the switchcase commands...but... I'm having syntax problems now.
Errors are commented in the code uploaded below starting with Error:
IRremote library is located on somewhere on this page : http://tronixstuff.wordpress.com/2011/03/30/tutorial-arduino-and-infra-red-control/
UPDATE 2:
Eureka! With help of both Ro-Bot-X and Basile I have finally got my code and bot to work! Look for it on the Robot page soon!