//#include <Wire.h>
char c=0;
//L2
int m1= 8;//forward
int m12=7;//forward
int m2=5;//end point
int m22=4;//end point
//L1
int m3=9;//circle
int m32=10;//circle
//L3
int m4=11;
int m42=12;
//for chasis
int m5= 3;//forward
int m52=2;//reverse
void L1();
void L11();
void L1_stop();
void L2_stop();
void gripper_stop();
void L2();
void L22();
void gripper();
void grip();
void L3();
void L33();
void L3_stop();
void sensor();
void robo_forward();
void robo_reverse();
void robo_stop();
char state;
void rice();
void sugar();
void dal();
void stop_all();
void setup() {
Serial.begin (9600);
pinMode(m1, OUTPUT);
pinMode(m12, OUTPUT);
pinMode(m2,OUTPUT);
pinMode(m22,OUTPUT);
pinMode(m3,OUTPUT);
pinMode(m32,OUTPUT);
pinMode(m4,OUTPUT);
pinMode(m42,OUTPUT);
pinMode(m5,OUTPUT);
pinMode(m52,OUTPUT);
}
void L1_stop()
{
digitalWrite(m3,LOW);
digitalWrite(m32,LOW);
}
void L1()// rotation
{
digitalWrite(m3,HIGH);
digitalWrite(m32,LOW);
}
void L11()//anticlockwise rotation
{
digitalWrite(m3,LOW);
digitalWrite(m32,HIGH);
}
void L2_stop()
{
digitalWrite(m1,LOW);
digitalWrite(m12,LOW);
}
void L2()//bending arm
{
digitalWrite(m1,LOW);
digitalWrite(m12,HIGH);
}
void L22()//arm up
{
digitalWrite(m1,HIGH);
digitalWrite(m12,LOW);
}
void gripper_stop()
{
digitalWrite(m2,LOW);
digitalWrite(m22,LOW);
}
void gripper()
{
digitalWrite(m2,HIGH);
digitalWrite(m22,LOW);
}
void grip()
{
digitalWrite(m2,LOW);
digitalWrite(m22,HIGH);
}
void L3_stop()
{
digitalWrite(m4,LOW);
digitalWrite(m42,LOW);
}
void L3()
{
digitalWrite(m4,LOW);
digitalWrite(m42,HIGH);
}
void L33()
{
digitalWrite(m4,HIGH);
digitalWrite(m42,LOW);
}
void robo_forward()
{
digitalWrite(m5,HIGH);
digitalWrite(m52,LOW);
}
void robo_reverse()
{
digitalWrite(m5,LOW);
digitalWrite(m52,HIGH);
}
void robo_stop()
{
digitalWrite(m5,LOW);
digitalWrite(m52,LOW);
}
void loop() {
if(Serial.available()>0)
{
while(Serial.available()!=1)
{
state=Serial.read();
Serial.print(state);
}
}
switch(state)
{
case 'k':rice();
state=0;
break;
case 'z':sugar();
state=0;
break;
case 'b': dal();
state=0;
break;
default: stop_all();
break;
}
}
void rice()
{
// if(state=='k')//rice
// {
int i;
Serial.print("2");
robo_forward();
delay(500);
robo_stop();
delay(50);
gripper();
delay(1500);
gripper_stop();
delay(50);
for(i=0;i<8;i++)
{
L2();
delay(50);
L2_stop();
delay(35);
}
L2_stop();
delay(50);
grip();
delay(1700);
L22();
delay(600);
L2_stop();
delay(50);
L1();
delay(1200);
L1_stop();
delay(50);
for(i=0;i<8;i++)
{
L2();
delay(50);
L2_stop();
delay(35);
}
L2_stop();
delay(50);
gripper_stop();
delay(50);
gripper();
delay(1500);
grip();
delay(1700);
gripper_stop();
delay(50);
L22();
delay(600);
L2_stop();
delay(50);
L11();
delay(910);
L1_stop();
delay(50);
robo_reverse();
delay(490);
robo_stop();
state=0;
}
void sugar()
{
//else if(state=='b')//sugar
//{
int i;
gripper();
delay(1500);
gripper_stop();
delay(50);
for(i=0;i<8;i++)
{
L2();
delay(50);
L2_stop();
delay(35);
}
L2_stop();
delay(50);
grip();
delay(1700);
L22();
delay(600);
L2_stop();
delay(50);
L1();
delay(1200);
L1_stop();
delay(50);
for(i=0;i<8;i++)
{
L2();
delay(50);
L2_stop();
delay(35);
}
L2_stop();
delay(50);
gripper_stop();
delay(50);
gripper();
delay(1500);
grip();
delay(1700);
gripper_stop();
delay(50);
L22();
delay(600);
L2_stop();
delay(50);
L11();
delay(910);
L1_stop();
delay(50);
state=0;
}
void dal()
{
//else if(state=='z')//dal
//{
int i;
Serial.print("2");
robo_reverse();
delay(520);
robo_stop();
delay(50);
gripper();
delay(1500);
gripper_stop();
delay(50);
for(i=0;i<8;i++)
{
L2();
delay(50);
L2_stop();
delay(35);
}
L2_stop();
delay(50);
grip();
delay(1700);
L22();
delay(600);
L2_stop();
delay(50);
L1();
delay(1200);
L1_stop();
delay(50);
for(i=0;i<8;i++)
{
L2();
delay(50);
L2_stop();
delay(35);
}
L2_stop();
delay(50);
gripper_stop();
delay(50);
gripper();
delay(1500);
grip();
delay(1700);
gripper_stop();
delay(50);
L22();
delay(600);
L2_stop();
delay(50);
L11();
delay(910);
L1_stop();
delay(50);
robo_forward();
delay(520);
robo_stop();
state=0;
}
void stop_all()
{
//else
//{
L1_stop();
L2_stop();
L3_stop();
gripper_stop();
robo_stop();
}
Comments