I'm having trouble with this project, is divided in 2 first when I write an l with the phone an RGB lights on all the colors, everything right there.
The PROBLEM comes when I control the servo, I'm trying that each time it receives a 'd' the servo turns 5 degrees more until reaches the limits 170°. The PROBLEM is that it does the first time, from 10° to 15°, but the next ones don't do anything.
I checked the Serial Monitor and the degrees are changing but the servo don't take them in account. Please help, and thank you.
#include <SoftwareSerial.h>
#include <Servo.h>
char c;
int deg = 10;
int res=0;
int res2=0;
Servo m;
//SoftwareSerial BT1(2,4); // RX, TX
void setup()
{ Serial.begin(9600);
pinMode(11,OUTPUT);
pinMode(12,OUTPUT);
pinMode(13,OUTPUT);
}
void loop(){
if (Serial.available()) // leer Serial
{ c = Serial.read() ;
Serial.println(c);
}
if (c == 'l'){
digitalWrite(11,HIGH);
digitalWrite(12,HIGH);
digitalWrite(13,HIGH);
}else {
digitalWrite(11,LOW);
digitalWrite(12,LOW);
digitalWrite(13,LOW);
}
if(c=='d'){
m.attach(3);
if (deg >= 10 && deg <= 165){
deg = deg + 5;
m.write(deg);
Serial.print(deg);
// m.detach(3);}
c = Serial.read() ;
}else{
m.write(10);
}
}