Please help me , I have a project RGB strip android arduino bluetooth , i have two different programs for arduino ,and i want to combine it together , i completed my application for android using MIT app inventor but just i want to combine these two different programs together
first program : ( buttons to control color of rgb led on my android app. )
#include <SoftwareSerial.h>
SoftwareSerial BT(10, 11);
String color;
void setup() {
BT.begin(9600);
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
}
void loop() {
while (BT.available()){
delay(10);
char c = BT.read ();
color += c;
}
if (color.length() > 0) {
Serial.println(color);
if (color == "blue")
{
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
delay(20);
}
else if (color == "green")
{
digitalWrite(2, LOW);
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
delay(20);
}
else if (color == "red")
{
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, HIGH);
delay(20);
}
else if (color == "stop")
{
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
delay(20);
}
}
color ="";}}
and the second program is , ( sliders to control brightness of rgb led on my android app. )
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX
const int RedPin = 4;
const int GreenPin = 3;
const int BluePin = 2;
int CurrentRed=0;
int CurrentGreen=0;
int CurrentBlue=0;
void setup(){
pinMode(RedPin,OUTPUT);
pinMode(GreenPin,OUTPUT);
pinMode(BluePin,OUTPUT);
Serial.begin(9600);
mySerial.begin(9600);
}
void loop(){
int ChangeDelay = 1000;
int RedStepSize = 25;
int GreenStepSize = 20;
int BlueStepSize = 1;
while(mySerial.available())
{
IncomingChar (mySerial.read ());
}
}
void SetAnalogColorCode(byte RedCode, byte GreenCode, byte BlueCode){
analogWrite(RedPin,RedCode);
analogWrite(GreenPin,GreenCode);
analogWrite(BluePin,BlueCode);
}
void IncomingChar (const byte InChar)
{
static char InLine [500]; //Hope we don't get more than that in one line
static unsigned int Position = 0;
switch (InChar)
{
case '\r': // Don't care about carriage return so throw away.
break;
case '|':
InLine [Position] = 0;
ProcessCommand(String(InLine));
Position = 0;
break;
default:
InLine [Position++] = InChar;
}
}
void ProcessCommand(String InLine){
Serial.println("InLine: " + InLine);
if (InLine.charAt(0) == 'R'){
Serial.println("Current Red = " + InLine.substring(2));
CurrentRed=InLine.substring(2).toInt();
}
if (InLine.charAt(0) == 'G'){
Serial.println("Current Green = " + InLine.substring(2));
CurrentGreen=InLine.substring(2).toInt();
}
if (InLine.charAt(0) == 'B'){
Serial.println("Current Blue = " + InLine.substring(2));
CurrentBlue=InLine.substring(2).toInt();
}
SetAnalogColorCode(CurrentRed, CurrentGreen, CurrentBlue);
}