Tuesday, November 6, 2012

Week 3 and 4 : The Programming for the movement of robot

 I have to write the program for my robot and burn into the ATM328P which also known as the Arduino. 



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