Hallo,
ich habe ein akutes Problem bei der Verheiratung von 2 Codes:
1.Anwendung: Ich möchte über Bluetooth Sensordaten auslesen und Eingaben machen.
2.Anwendung: Ich möchte über 2 Gebläse und eine Pumpe ansteuern über eine Bluetooth Konsole vom Handy.
Ich werde noch wahnsinnig, weil beide codes für sich tadellos funktionieren.
CODE1:
</#include <SoftwareSerial.h>
SoftwareSerial BTserial(8, 9); // RX, TX
char c=' ';
boolean NL = true;
void setup()
{
Serial.begin(9600);
Serial.print("Sketch: "); Serial.println(FILE);
Serial.print("Uploaded: "); Serial.println(DATE);
Serial.println(" ");
BTserial.begin(9600);
Serial.println("BTserial started at 38400");
Serial.println(" ");
}
void loop()
{
// Read from the Bluetooth module and send to the Arduino Serial Monitor
if (BTserial.available())
{
c = BTserial.read();
Serial.write(c);
}
// Read from the Serial Monitor and send to the Bluetooth module
if (Serial.available())
{
c = Serial.read();
BTserial.write(c);
// Echo the user input to the main window. The ">" character indicates the user entered text.
if (NL) { Serial.print(">"); NL = false; }
Serial.write(c);
if (c==10) { NL = true; }
}
}
/>
CODE2:
</#define PUMPE 5
#define GEBLAESE1 6
#define GEBLAESE2 7
int i;
char sendeInhalt = ' ';
void setup() {
pinMode(PUMPE, OUTPUT);
pinMode(GEBLAESE1, OUTPUT);
pinMode(GEBLAESE2, OUTPUT);
Serial.begin(9600);
}
void loop() {
if (Serial.available() > 0) //"wenn ein Datenpaket geliefert wird"
{
sendeInhalt = Serial.read(); //liest die Daten
if (sendeInhalt == '1') { analogWrite(PUMPE,255); //half speed
Serial.println ("Pumpe an");
} //Pumpe an
if (sendeInhalt == '0') { analogWrite(PUMPE, 0);
Serial.println ("Pumpe aus");
} //Pumpe aus
if (sendeInhalt == 'A') { analogWrite(GEBLAESE1,255); //half speed
Serial.println ("Geblaese1 an");
} //Pumpe an
if (sendeInhalt == 'B') { analogWrite(GEBLAESE1, 0);
Serial.println ("Geblaese1 aus");
} //Pumpe aus
if (sendeInhalt == 'C') { analogWrite(GEBLAESE2,255); //half speed
Serial.println ("Geblaese2 an");
} //Pumpe an
if (sendeInhalt == 'D') { analogWrite(GEBLAESE2, 0);
Serial.println ("Geblaese2 aus");
} //Pumpe aus
Serial.flush(); //seriellen Puffer löschen
}
}
/>
Ich wollte beide Codes durch eine Oder Bedingung verknüpfen
ungefähr so:
if (BTserial.available() || Serial.available())
das funktioniert aber nicht ..
Jemand eine Idee, wie ich beide verheiraten könnte?
Gruß
Rimbo
