Vous êtes sur la page 1sur 3

#include <Servo.

h>
Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;
int angle = 0;
void setup() {
Serial.begin(9600);//
servo1.attach(8); // attach the signal pin of servo to pin9 of arduino
servo2.attach(9);
servo3.attach(10);
servo4.attach(11);
}

void loop() {
if(Serial.available()>0)
{
char data= Serial.read(); // reading the data received from the bluetooth
module
switch(data)
{
case '1': base();break; // when a is pressed on the app on your smart phone
case '2': base1;break; // when d is pressed on the app on your smart phone
case '3': right();break; // when a is pressed on the app on your smart
phone
case '4': right1();break; // when d is pressed on the app on your smart
phone
case '5': left();break; // when a is pressed on the app on your smart phone
case '6': left1();break; // when d is pressed on the app on your smart
phone
case '7': pickup();break; // when a is pressed on the app on your smart
phone
case '8': pickup1();break; // when d is pressed on the app on your smart
phone
default : break;
}
Serial.println(data);
}
delay(50);
}
void base()
{
for(angle = 0; angle < 180; angle += 1) // command to move from 0 degrees to
180 degrees
{
servo1.write(angle); //command to rotate the servo to the
specified angle
delay(15);
}
delay(1000);
}
void base1()
{
for(angle = 180; angle>=0; angle-=1) // command to move from 180 degrees to 0
degrees
{
servo1.write(angle); //command to rotate the servo to the
specified angle
delay(5);
}
delay(1000);
}
void right()
{
for(angle = 0; angle <180; angle += 1) // command to move from 0 degrees to
180 degrees
{
servo2.write(angle); //command to rotate the servo to the
specified angle
delay(15);
}
}
void right1()
{
for(angle =180; angle>=0; angle-=1) // command to move from 180 degrees to 0
degrees
{
servo2.write(angle); //command to rotate the servo to the
specified angle
delay(5);
}
delay(1000);
}
void left()
{
for(angle =0; angle < 180; angle += 1) // command to move from 0 degrees to
180 degrees
{
servo3.write(angle); //command to rotate the servo to the
specified angle
delay(15);
}
delay(1000);
}
void left1()
{

for(angle =180; angle>=0; angle-=1) // command to move from 180 degrees to 0


degrees
{
servo3.write(angle); //command to rotate the servo to the
specified angle
delay(5);
}
delay(1000);
}
void pickup()
{
for(angle = 0; angle < 180; angle += 1) // command to move from 0 degrees to
180 degrees
{
servo4.write(angle); //command to rotate the servo to the
specified angle
delay(15);
}
delay(1000);
}
void pickup1()
{

for(angle =180; angle>=0; angle-=1) // command to move from 180 degrees to 0


degrees
{
servo4.write(angle); //command to rotate the servo to the
specified angle
delay(5);
}
delay(1000);
}

Vous aimerez peut-être aussi