#include <SoftwareSerial.h> // TX RX software library for bluetooth
#include <Servo.h> // servo library
Servo myservo; // servo name
int bluetoothTx = 10; // bluetooth tx to 10 pin
int bluetoothRx = 11; // bluetooth rx to 11 pin
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);
void setup()
{
myservo.attach(9); // attach servo signal wire to pin 9
//Setup usb serial connection to computer
Serial.begin(9600);
//Setup Bluetooth serial connection to android
bluetooth.begin(9600);
}
void loop()
{
//Read from bluetooth and write to usb serial
if(bluetooth.available()> 0 ) // receive number from bluetooth
{
int servopos = bluetooth.read(); // save the received number to servopos
Serial.println(servopos); // serial print servopos current number received from bluetooth
myservo.write(servopos); // roate the servo the angle received from the android app
}
}
#include <Servo.h>
Servo Mservo; // create servo object to control a servo
// twelve servo objects can be created on most boards
int pos = 90; // variable to store the servo position
void setup() {
Mservo.attach(6); // attaches the servo on pin 6 to the servo object
}
void loop() {
for (pos = 90; pos <= 180; pos += 5) { // goes from 90 degrees to 180 degrees
// in steps of 1 degree
Mservo.write(pos); // tell servo to go to position in variable 'pos'
delay(10); // waits 10ms for the servo to reach the position
}
for (pos = 180; pos >= 90; pos -= 1) { // goes from 180 degrees to 90 degrees
Mservo.write(pos); // tell servo to go to position in variable 'pos'
delay(10); // waits 10ms for the servo to reach the position
}
}
here i mixed two codes in the same program,the 1st one is to control a servo through bluetooth and the 2nd one is to control a servo to move from 90 -180 degrees with a switch,after this i got an error "exit one redefinition of 'void setup()' ".Can anyone help me in this problem.