Asus zenfone 2 laser (black)

Minefield Project of ROBOTIX 2015 in IIT KGP

TUITORALS :    GET IT FROM HERE

CODE :

int groundpin = 18; // analog input pin 4
int powerpin = 19; // analog input pin 5
int xpin = 3; // x-axis of the accelerometer
int ypin = 2; // y-axis
int zpin = 1; // z-axis (only on 3-axis models)

int rmf=2;
int rmr=3;
int lmf=4;
int lmr=5;

void setup()
{
Serial.begin(9600);
pinMode(xpin,INPUT);
pinMode(ypin,INPUT);
pinMode(zpin,INPUT);
pinMode(rmf,OUTPUT);
pinMode(rmr,OUTPUT);
pinMode(lmf,OUTPUT);
pinMode(lmr,OUTPUT);
}

void loop()
{
 int x=analogRead(xpin);
 int y=analogRead(ypin);
 int z=analogRead(zpin);
 
Serial.print(x);
Serial.print(" ");
Serial.print(y);
Serial.print(" ");
Serial.print(z);
Serial.println();
delay(100);

if(x>=400 && x<=420)
{
  stopp();
}
if(x>=385 && x<=399)
{
  forward();
}
if(x>=350 && x<=375)
{
  back();
}
if(z>=275 && z<=295)
{
  right();
}
if(z>=350 && z<=400)
{
  left();
}
}

void stopp()
{
  digitalWrite(rmf,LOW);
  digitalWrite(lmf,LOW);
  digitalWrite(rmr,LOW);
  digitalWrite(lmr,LOW);
}
void forward()
{
  digitalWrite(rmf,HIGH);
  digitalWrite(lmf,HIGH);
  digitalWrite(rmr,LOW);
  digitalWrite(lmr,LOW);
}
void back()
{
  digitalWrite(rmf,LOW);
  digitalWrite(lmf,LOW);
  digitalWrite(rmr,HIGH);
  digitalWrite(lmr,HIGH);
}
void right()
{
  digitalWrite(rmf,LOW);
  digitalWrite(lmf,HIGH);
  digitalWrite(rmr,HIGH);
  digitalWrite(lmr,LOW);
}
void left()
{
  digitalWrite(rmf,HIGH);
  digitalWrite(lmf,LOW);
  digitalWrite(rmr,LOW);
  digitalWrite(lmr,HIGH);
}
 
 
TESTED & WORKED WELL !


No comments:

Post a Comment