Below is my
program for the robot using C language:
#include <math.h>
int backLight = 13;
#include <math.h>
int analogPin0 = 0;
// potentiometer wiper (middle terminal) connected to analog pin 2
int analogPin1 = 1;
// potentiometer wiper (middle terminal) connected to analog pin 3
int analogPin2 = 2;
// potentiometer wiper (middle terminal) connected to analog pin 4
int hba = 2;
int hbb = 6;
int hb0 = 9;
int hb1 = 10;
int hb2 = 11;
int hb3 = 12;
float val;
int val0;
int val1;
int val2;
void setup()
{
pinMode(backLight, OUTPUT);
delay(1000);
}
void loop()
{
digitalWrite(hba, LOW);
digitalWrite(hbb, LOW);
digitalWrite(hb0, LOW);
digitalWrite(hb1, HIGH);
digitalWrite(hb2, LOW);
digitalWrite(hb3, HIGH);
delay(100);
}
else if (val1<=250 && val>=32)
{
digitalWrite(hba, HIGH);
digitalWrite(hbb, HIGH);
digitalWrite(hb0, LOW);
digitalWrite(hb1, HIGH);
digitalWrite(hb2,
LOW);
digitalWrite(hb3, HIGH);
delay(100);
}
else if (val1>250 && val<32)
{
if (val0<val2)
{
digitalWrite(hba, LOW);
digitalWrite(hbb, LOW);
digitalWrite(hb0, LOW);
digitalWrite(hb1, LOW);
digitalWrite(hb2, LOW);
digitalWrite(hb3, HIGH);
delay(500);
}
else if (val2<val0)
{
digitalWrite(hba, LOW);
digitalWrite(hbb, LOW);
digitalWrite(hb0, LOW);
digitalWrite(hb1, HIGH);
digitalWrite(hb2, LOW);
digitalWrite(hb3, LOW);
delay(500);
}
}
else if (val1>250 && val>=32)
{
if (val0<val2)
{
digitalWrite(hba, HIGH);
digitalWrite(hbb, HIGH);
digitalWrite(hb0, LOW);
digitalWrite(hb1, LOW);
digitalWrite(hb2, LOW);
digitalWrite(hb3, HIGH);
delay(500);
}
else if (val2<val0)
{
digitalWrite(hba, HIGH);
digitalWrite(hbb, HIGH);
digitalWrite(hb0, LOW);
digitalWrite(hb1, HIGH);
digitalWrite(hb2, LOW);
digitalWrite(hb3, LOW);
delay(500);
}
}
}
No comments:
Post a Comment