Hi i'm trying to make a RGB controler via bluetooth i am using an old HC-05 module, and an android interace made in basic4android IDE.
in the interface i have 3 Seekbar in order to control the 3 pwm for the RGB led.
i wont post all my android code due the extencion of this, but if someone want it just ask it.
the data send part basicly sends 3 parts like
Tx.WriteLine("#"& SeekBar1.Value &"R" ) so thats only for one seekbar it sends delimitation characters in order to know what value its for.
this is for Green seekbar
Tx.WriteLine("#"& SeekBar1.Value &"G" )
and Blue seekbar
Tx.WriteLine("#"& SeekBar1.Value &"B" )
belong this i have my arduino code but it just not working as i espected.
i hope you can find my error and help me i think maybe its something i'm not seeing but who knows. BTW i'm mexican so i apologize for my english i know its not good enough at least as i wanted to be.
/*-----------------------------------------------------
CONTROL DE GIRO DE MOTORES PARA SHIELD COMPATIBLE CON ARDUINO Y PINGUINO GENTOO
-----------------------------------------------------*/
byte DATO_RECIBIDO;
int LED_ROJO =0;
int LED_VERDE =0;
int LED_AZUL=0;
int x=0;
int inicio;
int fin;
int convercion;
char caracter [6]={0,0,0,0,0,0};
//rutinas
void setup() {
// put your setup code here, to run once:
/*pinMode(9,OUTPUT);
pinMode(10,OUTPUT); // DECLARA LA SALIDA DEL MOTOR DER COMO SALIDA
pinMode(11,OUTPUT); // DECLARA MOTOR IZQUIERDO COMO SALIDA
pinMode(12,OUTPUT);
pinMode(13,OUTPUT);
*/
Serial.begin(9600); // abilita el puerto serial y define la velocidad del puerto serie o BAUDRATE DEL UART
}
void loop() {
// put your main code here, to run repeatedly:
if (Serial.available())// el micro pregunta si se ha recivido algun dato
{
caracter[x] = Serial.read(); //OBTIENE EL DATO Y LO GUARDA IMPORTANTE!
}
if (caracter[x]=='#') //pregunta si ya llego el primer dato
{
inicio=1;
}
if (inicio==1)
{
x=x+1;
}
if (caracter[x]=='R'||caracter[x]=='G'||caracter[x]=='B')//pregunta si ya llego el ultimo dato
{
fin=x-1;
inicio=0;
x=0;
}
if (fin==1){
convercion=(caracter [1]-48);}
if (fin==2){
convercion=(caracter[1]-48)*10+(caracter[2]-48);}
if (fin==3){
convercion=(caracter[1]-48)*100+(caracter[2]-48)*10+(caracter[3]-48);}
if (fin==4){
convercion=(caracter[1]-48)*1000+(caracter[2]-48)*100+(caracter[3]-48)*10+(caracter[4]-48);}
if(caracter[fin+1]=='R'){
LED_ROJO=convercion;
analogWrite(9,LED_ROJO);
}
if(caracter[fin+1]=='G'){
LED_VERDE=convercion;
analogWrite(10,LED_VERDE);
}
if(caracter[fin+1]=='B'){
LED_AZUL=convercion;
analogWrite(11,LED_AZUL);
}