Robot wireless mode select
hi, have built , programed robot follows me around, need build wireless controller can use toggle between modes "follow me" , "stay put". build simple wireless controller using single pole double throw switch , these? http://www.banggood.com/433mhz-rf-transmitter-with-receiver-kit-for-arduino-arm-mcu-wireless-p-74102.html?currency=usd&utm_source=google&utm_medium=shopping&utm_content=miko_ruby&utm_campaign=electronic-xie-us&gclid=ciy185wzlb0cfejf7aodwhwazg can't use ir because interfere current programing
go here more info: http://forum.arduino.cc/index.php?topic=222510.0
code: [select]
#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 - library/class 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 2 8bit-i2c address 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; < 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 = 0; < 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 more info: http://forum.arduino.cc/index.php?topic=222510.0
if simple toggle switch, may want 1 of these. still might little on kill, 4 buttons should allow add more features follow , stay. 315mhz wireless remote + receiver
Arduino Forum > Using Arduino > Project Guidance > Robot wireless mode select
arduino
Comments
Post a Comment