Five SeekBars Android to control 5 ServoMotors

hi ,

I 'm from Brazil I'm developing a master's research in innovation and technology that have to control a prosthetic hand Bionic Android interface. My question is how to differentiate progress bars on the Arduino code. I'm the Android angle and by sending an identification , for example " 180a " or " 100b " or 60a ....
I managed to differentiate the bars and off an LED, but my problem is how to control the Servant , because the angle is not being interpreted . Below the code I'm using , if someone wants to contribute to the research thanks :

#include <SoftwareSerial.h>
#include <Servo.h>

Servo servo1;
Servo servo2;
SoftwareSerial bluetooth(10, 11); // RX, TX
char readBluetooth;
int lamp=13;
char buffer[4];
int received;
String teste;

void setup(){

bluetooth.begin(9600);

servo1.attach(3);
servo2.attach(4);
pinMode(lamp,OUTPUT);

received=0;
}

void loop(){

if(bluetooth.available()){

char c = (char)bluetooth.read();

if(c=='a'){
int numero = atoi(buffer);
received=0;
digitalWrite(lamp,HIGH);
servo1.write(numero);
}else if(c=='b'){
int numero = atoi(buffer);
if(numero>=60){
servo2.write(numero);
received=0;
}
digitalWrite(lamp,LOW);
received=0;

}
else if(c!='a'&&c!='b'){
buffer[received++]=c;

}
}
bluetooth.flush();
}

I'm developing a master's research in innovation and technology

And yet you can't be bothered to read the topics at the top of the forum, the ones that say "Read this BEFORE posting in this forum"?

My question is how to differentiate progress bars on the Arduino code.

Send the information intelligently.

Below the code I'm using , if someone wants to contribute to the research

That code is NOT posted properly, so why should we?

 if(bluetooth.available()){
   
   char c = (char)bluetooth.read();
 
   
   if(c=='a'){
    int numero = atoi(buffer);

Please point out WHERE you stored anything in buffer.

Servo code that might be close to what you are looking for. You can test with the serial monitor.

//zoomkat 11-22-12 simple delimited ',' string parse 
//from serial port input (via serial monitor)
//and print result out serial port
//multi servos added 
// Powering a servo from the arduino usually *DOES NOT WORK*.

String readString;
#include <Servo.h> 
Servo myservoa, myservob, myservoc, myservod;  // create servo object to control a servo 

void setup() {
  Serial.begin(9600);

  //myservoa.writeMicroseconds(1500); //set initial servo position if desired

  myservoa.attach(6);  //the pin for the servoa control
  myservob.attach(7);  //the pin for the servob control
  myservoc.attach(8);  //the pin for the servoc control
  myservod.attach(9);  //the pin for the servod control 
  Serial.println("multi-servo-delimit-test-dual-input-11-22-12"); // so I can keep track of what is loaded
}

void loop() {

  //expect single strings like 700a, or 1500c, or 2000d,
  //or like 30c, or 90a, or 180d,
  //or combined like 30c,180b,70a,120d,

  if (Serial.available())  {
    char c = Serial.read();  //gets one byte from serial buffer
    if (c == ',') {
      if (readString.length() >1) {
        Serial.println(readString); //prints string to serial port out

        int n = readString.toInt();  //convert readString into a number

        // auto select appropriate value, copied from someone elses code.
        if(n >= 500)
        {
          Serial.print("writing Microseconds: ");
          Serial.println(n);
          if(readString.indexOf('a') >0) myservoa.writeMicroseconds(n);
          if(readString.indexOf('b') >0) myservob.writeMicroseconds(n);
          if(readString.indexOf('c') >0) myservoc.writeMicroseconds(n);
          if(readString.indexOf('d') >0) myservod.writeMicroseconds(n);
        }
        else
        {   
          Serial.print("writing Angle: ");
          Serial.println(n);
          if(readString.indexOf('a') >0) myservoa.write(n);
          if(readString.indexOf('b') >0) myservob.write(n);
          if(readString.indexOf('c') >0) myservoc.write(n);
          if(readString.indexOf('d') >0) myservod.write(n);
        }
         readString=""; //clears variable for new input
      }
    }  
    else {     
      readString += c; //makes the string readString
    }
  }
}

Thanks Zoomkat.

I will test the code. Thanks for contributing.

Hi,
I tested the code but to no avail , the motor does not rotate .

I'm working with bluetooth , so I configured :

#include < SoftwareSerial.h >
bluetooth.begin (9600 ) ;
if ( bluetooth.available () ) {...

But still could not.

For bluetooth is the same procedure ?

For bluetooth is the same procedure ?

Yes, assuming that you actually get anything from the bluetooth device.

What does you serial output tell you is happening?

Where is YOUR code? In code tags!

This is my code:

But the servo no execute correctly.

#include <SoftwareSerial.h>
#include <Servo.h>

Servo servo1;//Variavel meuservoT do tipo Servo
Servo servo2;
SoftwareSerial bluetooth(10, 11); // RX, TX
char readBluetooth;//Variável que irá receber o valor enviado do celular para o bluetooth
int lamp=13;//LED da porta 13
char buffer[4];
int received;
String teste;

void setup(){

bluetooth.begin(9600);//Inicia Comunicação com Bluetooth

servo1.attach(3);// porta 3 para o Motor
servo2.attach(4);
pinMode(lamp,OUTPUT);//Definindo o pino 13 como saída

// servo1.write(0);
received=0;
}

void loop(){

if(bluetooth.available()){

char c = (char)bluetooth.read();

if(c=='a'){

String valor = buffer;//recebe Valor do buffer como String
String angulo = valor.substring(1,1);//Cria uma variavel com o angulo por exemplo: 38a, captura somente 38
int angulo2 = angulo.toInt();//converte o angulo para inteiro
servo1.write(angulo2);
received=0;
digitalWrite(lamp,HIGH);

}else if(c=='b'){
int numero = atoi(buffer);
if(numero>=60){
// servo2.write(numero);
received=0;
}
digitalWrite(lamp,LOW);
received=0;

}
else if(c!='a'&&c!='b'){
buffer[received++]=c;
//digitalWrite(lamp,HIGH);
}
}
bluetooth.flush();
}

If you want to receive data for 5 servos the simplest way is always to send 5 values in the same order separated by commas.

Look at the examples in serial input basics - especially the 3rd example.

...R

But the servo no execute correctly.

Have you gotten a servo to control properly when directly controlled from the arduino without using bluetooth?

The "string" that you think you are receiving is NOT a string. A string is a NULL terminated array of chars. Not a NULL terminator in sight in your code. Do NOT pass things that are not strings to functions that expect strings.