Hi, I have built and programed a robot that follows me around, what i now need to do is build a wireless controller that i can use to toggle it between the modes "Follow Me" and "Stay Put". Could i build a simple wireless controller using a single pole double throw switch and these? 433Mhz RF Decoder Transmitter With Receiver Module Kit For ARM MCU Wireless Geekcreit for Arduino - products that work with official Arduino boards Sale - Banggood USA I can't use IR because that would interfere with the current programing which is this
#include <Wire.h>
const int pingPin = 11;
unsigned int duration, inches;
int LeftF= 5;
int RightF= 2;
int LeftB= 3;
int RightB= 4;
/*
IRSeeker.ino - A library/class for the HiTechnic IRSeeker V2 infrared sensor.
*/
struct InfraredResult
{
byte Direction;
byte Strength;
};
class InfraredSeeker
{
public:
static void Initialize();
static boolean Test();
static void ReadACRaw(byte* buffer);
static void ReadDCRaw(byte* buffer);
static InfraredResult ReadAC();
static InfraredResult ReadDC();
static int DirectionAngle(byte Direction);
private:
static InfraredResult PopulateValues(byte* buffer);
static void ReadValues(byte OffsetAddress, byte* buffer);
static const int Address = 0x10 / 2; //Divide by two as 8bit-I2C address is provided
};
void InfraredSeeker::Initialize()
{
Wire.begin();
Wire.beginTransmission(InfraredSeeker::Address);
Wire.write(0x00);
Wire.endTransmission();
while(Wire.available() > 0)
Wire.read();
}
boolean InfraredSeeker::Test()
{
Wire.beginTransmission(InfraredSeeker::Address);
Wire.write(0x08);
Wire.endTransmission();
Wire.requestFrom(InfraredSeeker::Address, 16);
char Manufacturer_Model[16];
while(Wire.available() < 16);
for(byte i=0; i < 16; i++)
{
Manufacturer_Model[i] = Wire.read();
}
while(Wire.available() > 0)
Wire.read();
return strncmp(Manufacturer_Model, "HiTechncNewIRDir", 16)==0;
}
void InfraredSeeker::ReadValues(byte OffsetAddress, byte* buffer)
{
Wire.beginTransmission(InfraredSeeker::Address);
Wire.write(OffsetAddress);
Wire.endTransmission();
Wire.requestFrom(InfraredSeeker::Address, 6);
while(Wire.available() < 6);
for(byte i = 0; i < 6; i++)
{
buffer[i] = Wire.read();
}
while(Wire.available() > 0)
Wire.read();
}
void InfraredSeeker::ReadACRaw(byte* buffer)
{
ReadValues(0x49, buffer);
}
void InfraredSeeker::ReadDCRaw(byte* buffer)
{
ReadValues(0x42, buffer);
}
InfraredResult InfraredSeeker::PopulateValues(byte* buffer)
{
InfraredResult Data;
Data.Direction = buffer[0];
if(buffer[0] != 0)
{
if(buffer[0] % 2 == 0)
{
Data.Strength = (buffer[buffer[0] / 2] + buffer[buffer[0] / 2 + 1]) / 2;
}
else
{
Data.Strength = buffer[buffer[0] / 2 + 1];
}
}
else
{
Data.Strength = 0;
}
return Data;
}
InfraredResult InfraredSeeker::ReadAC()
{
byte buffer[6];
ReadACRaw(buffer);
return PopulateValues(buffer);
}
InfraredResult InfraredSeeker::ReadDC()
{
byte buffer[6];
ReadDCRaw(buffer);
return PopulateValues(buffer);
}
int DirectionAngle(byte Direction)
{
return Direction * 30 - 150;
}
void setup()
{
pinMode(RightF,OUTPUT);
pinMode(LeftF,OUTPUT);
pinMode(LeftB,OUTPUT);
pinMode(RightB,OUTPUT);
Serial.begin(9600);
Serial.println("HiTechnic IRSeeker V2");
Serial.println();
Serial.println();
Serial.println("Dir\tAngle\tStrength");
Serial.println();
InfraredSeeker::Initialize();
}
void loop()
{
InfraredResult InfraredBall = InfraredSeeker::ReadAC();
Serial.print(InfraredBall.Direction);
Serial.print("\t");
Serial.print(DirectionAngle(InfraredBall.Direction));
Serial.print("\t");
Serial.print(InfraredBall.Strength);
Serial.println();
delay(200); //optional
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin, LOW);
pinMode(pingPin, INPUT);
duration = pulseIn(pingPin, HIGH);
inches = duration / 74 / 2;
Serial.println(inches);
delay(200);
if (InfraredBall.Direction >= 1 && InfraredBall.Direction < 5)
{
digitalWrite(RightF,HIGH);
digitalWrite(LeftB,HIGH);
digitalWrite(RightB,LOW);
digitalWrite(LeftF,LOW);
}
if (InfraredBall.Direction > 5 && InfraredBall.Direction <= 9)
{
digitalWrite(LeftF,HIGH);
digitalWrite(RightB,HIGH);
digitalWrite(RightF,LOW);
digitalWrite(LeftB,LOW);
}
if (InfraredBall.Direction == 5 && inches > 12)
{
digitalWrite(LeftF,HIGH);
digitalWrite(RightF,HIGH);
digitalWrite(RightB,LOW);
digitalWrite(LeftB,LOW);
}
if (InfraredBall.Direction == 5 && inches < 3)
{
digitalWrite(LeftB,HIGH);
digitalWrite(RightB,HIGH);
digitalWrite(RightF,LOW);
digitalWrite(LeftF,LOW);
}
if (InfraredBall.Direction == 5 && inches <= 12 && inches >= 3)
{
digitalWrite(LeftB,LOW);
digitalWrite(RightB,LOW);
digitalWrite(RightF,LOW);
digitalWrite(LeftF,LOW);
}
}
Go here for more info: Interpreting sensor input for robot. - Sensors - Arduino Forum