Archive | Code RSS feed for this section

Our code to draw fau

3 May
int pingPin=12;
long duration, cm;
float IR1;
float IR2;
void forward()
{
 analogWrite(11,100);
 analogWrite(10,95);
 digitalWrite(7,HIGH);
 digitalWrite(6,LOW);
 digitalWrite(9,HIGH);
 digitalWrite(8,LOW);
}
void rotateR()
{
 digitalWrite(7,HIGH);
 digitalWrite(6,LOW);
 digitalWrite(9,LOW);
 digitalWrite(8,HIGH);
 analogWrite(11,95);
 analogWrite(10,100);
}
void angleR(int degree)
{
 rotateR();
 delay(degree*(256/36));
 stop();
}
void rotateL()
{
 analogWrite(11,125);
 analogWrite(10,125);
 digitalWrite(6,HIGH);
 digitalWrite(7,LOW);
 digitalWrite(8,LOW);
 digitalWrite(9,HIGH);
}
void angleL(int degree)
{
 rotateL();
 delay(degree*(256/36));
 stop();
}
void stop()
{
 digitalWrite(6,HIGH);
 digitalWrite(7,HIGH);
 digitalWrite(8,HIGH);
 digitalWrite(9,HIGH);
 digitalWrite(11,LOW);
 digitalWrite(10,LOW);
}
void setup()
{
 pinMode(6,OUTPUT);
 pinMode(7,OUTPUT);
 pinMode(8,OUTPUT);
 pinMode(9,OUTPUT);
 pinMode(10,OUTPUT);
 pinMode(11,OUTPUT);
}
void ping()
{
 pinMode(pingPin, OUTPUT);
 digitalWrite(pingPin, LOW);
 delayMicroseconds(2);
 digitalWrite(pingPin, HIGH);
 delayMicroseconds(5);
 digitalWrite(pingPin, LOW);
}
void loop()
{
//forward();
//delay(3500);
//angleL(125);
//forward();
//delay(2500);
//stop();
//delay(8000);
 //forward();
 //delay(2000);
 //stop();
delay(1000);
forward();
delay(4000);
angleL(130);
forward();
delay(3500);
angleL(140);
forward();
delay(4000);
stop();
delay(5000);
//delay(1000);
//forward();
//delay(3500);
//stop();
//delay(3000);
}
Advertisements

How to make robot move right,left, forward and backwards.

16 Feb

int motor1a=13; //control pins for Motor1
int motor1b=12;
int motor2a=11; //control pins for Motor2
int motor2b=10;

int enableMotor1=9; //PWM Motor 1 Speed pin
int enableMotor2=8; //PWM Motor 2 Speed pin

void forward(int speed) //function to move forward at a defined speed (0-255)
{
digitalWrite(motor1a, HIGH); //set motor 1 direction
digitalWrite(motor1b, LOW);
digitalWrite(motor2a, HIGH); //set motor 2 direction
digitalWrite(motor2b, LOW);
analogWrite(enableMotor1, speed); //set motor 1 speed (0-255)
analogWrite(enableMotor2, speed); //set motor 2 speed (0-255)
}

void reverse(int speed)
{

digitalWrite(motor1a, LOW); //set motor 1 direction
digitalWrite(motor1b, HIGH);
digitalWrite(motor2a, LOW); //set motor 2 direction
digitalWrite(motor2b, HIGH);
analogWrite(enableMotor1, speed); //set motor 1 speed (0-255)
analogWrite(enableMotor2, speed); //set motor 2 speed (0-255)

}
void left(int speed)
{
digitalWrite(motor1a, HIGH); //set motor 1 direction
digitalWrite(motor1b, LOW);
digitalWrite(motor2a, LOW); //set motor 2 direction
digitalWrite(motor2b, HIGH;
analogWrite(enableMotor1, speed); //set motor 1 speed (0-245)
analogWrite(enableMotor2, speed); //set motor 2 speed (0-133)

}
void right(int speed)
{
digitalWrite(motor1a, LOW); //set motor 1 direction
digitalWrite(motor1b, HIGH);
digitalWrite(motor2a, HIGH); //set motor 2 direction
digitalWrite(motor2b, LOW);
analogWrite(enableMotor1, speed); //set motor 1 speed (0-133)
analogWrite(enableMotor2, speed); //set motor 2 speed (0-245)

}

void stop()
{
digitalWrite(motor1a, HIGH); //set motor 1 direction
digitalWrite(motor1b, HIGH);
digitalWrite(motor2a, HIGH); //set motor 2 direction
digitalWrite(motor2b, HIGH);
}

void setup()
{
pinMode(motor1a, OUTPUT);
pinMode(motor1b, OUTPUT);
pinMode(motor2a, OUTPUT);
pinMode(motor2b, OUTPUT);
pinMode(enableMotor1, OUTPUT);
pinMode(enableMotor2, OUTPUT);
}

void loop()
{
forward(255); //go forward full speed
delay(2000); //for 2 secs
left(127); //turn left at 50% speed
delay(2000); //for 2 secs
reverse(255); //go reverse full speed
delay(1000); //for 1 sec
right(64); //turn right at 25% speed
delay(500); //for 0.5 secs
}

How to write code for a rectangle

15 Feb
 
Syntax: rect(x, y, width, height)
Example: rect(30, 20, 55, 55);

How to write code for a triangle

15 Feb
Triangle(30, 75, 58, 20, 86, 75);
Traingle(x1,y1,x2,y2,x3,y3);