wifi versus bluetooth
1 bericht
• Pagina 1 van 1
wifi versus bluetooth
Heb het volgende probleem als ik mijn code gebruik met bluetooth werkt deze goed zend ik echter een signaal via wifi met een esp8266 in ap modus wil hij geen letters ontvangen
voorbeeld ik zend A=20000 bij de bluetooth haalt hij wel de eerste twee tekens weg door dit stukje code
Bij de wifi wil hij het niet in Blt zetten wel cijfers maar niet als ik begin met een letter
wie kan mij hierbij helpen??
voorbeeld ik zend A=20000 bij de bluetooth haalt hij wel de eerste twee tekens weg door dit stukje code
- Code: Alles selecteren
joy=receivedChars[0];
if (joy=='D'){ z=0;receivedChars[0]='0';receivedChars[1]='0';}
if (joy=='A'){ z=1;receivedChars[0]='0';receivedChars[1]='0';} // beide motoren syncroon //joystick
if (joy=='B'){ z=2;receivedChars[0]='0';receivedChars[1]='0';} //beide motoren tegengesteld //joystick
if (joy=='C'){ z=3;receivedChars[0]='0';receivedChars[1]='0';} //beide motoren appart //joystick
if (joy=='V') {receivedChars[0]=' ';receivedChars[1]=' ';} //beide motoren appart //joystick
Bij de wifi wil hij het niet in Blt zetten wel cijfers maar niet als ik begin met een letter
- Code: Alles selecteren
#define HC06 Serial2 //arduino Library
boolean newData = false;
int z;
const byte numChars = 32;
char receivedChars[numChars]; // an array to store the received data
char joy;
int Blt = atol(receivedChars);
void setup() {
Serial.begin(9600);
Serial3.begin(9600);
HC06.begin(9600);
}
void loop() {
//------------WIFI-----------------------------I
static byte ndx = 0;
long now = millis();
char rc;
char endMarker = '>';
static long lastReceived= millis();
while (Serial3.available() && newData == false) {
rc = Serial3.read();
if (rc != endMarker) {
receivedChars[ndx] = rc;
ndx++;
if (ndx >= numChars) { ndx = numChars - 1; }
} else {
receivedChars[ndx] = '\0'; // terminate the string
ndx = 0;
newData = true;
lastReceived = now;
joy=receivedChars[0];
if (joy=='D'){ z=0;receivedChars[0]='0';receivedChars[1]='0';}
if (joy=='A'){ z=1;receivedChars[0]='0';receivedChars[1]='0';} // beide motoren syncroon //joystick
if (joy=='B'){ z=2;receivedChars[0]='0';receivedChars[1]='0';} //beide motoren tegengesteld //joystick
if (joy=='C'){ z=3;receivedChars[0]='0';receivedChars[1]='0';} //beide motoren appart //joystick
if (joy=='V') {receivedChars[0]=' ';receivedChars[1]=' ';} //beide motoren appart //joystick
Blt = atol(receivedChars);
if ((z>0)&&(!(joy=='V'))){
if((Blt<6000)||(Blt>10000)){Blt=30000;}
}}}
//------------BLUETOOTH-----------------------------I
while( (HC06.available()>0) &&( newData == false)) {
rc = HC06.read();
if (rc != endMarker) {
receivedChars[ndx] = rc;
ndx++;
if (ndx >= numChars) { ndx = numChars - 1; }
} else {
receivedChars[ndx] = '\0'; // terminate the string
ndx = 0;
newData = true;
lastReceived = now;
joy=receivedChars[0];
if (joy=='D'){ z=0;receivedChars[0]='0';receivedChars[1]='0';}
if (joy=='A'){ z=1;receivedChars[0]='0';receivedChars[1]='0';} // beide motoren syncroon //joystick
if (joy=='B'){ z=2;receivedChars[0]='0';receivedChars[1]='0';} //beide motoren tegengesteld //joystick
if (joy=='C'){ z=3;receivedChars[0]='0';receivedChars[1]='0';} //beide motoren appart //joystick
if (joy=='V') {receivedChars[0]=' ';receivedChars[1]=' ';} //beide motoren appart //joystick
Blt = atol(receivedChars);
if ((z>0)&&(!(joy=='V'))){
if((Blt<6000)||(Blt>10000)){Blt=30000;}
}}}
//if (now-lastReceived >2500){ failsave();}
Serial.print("joy= " );Serial.println(joy );
Serial.print(receivedChars);Serial.print(" Blt= ");Serial.println(Blt);
newData = false;
}
wie kan mij hierbij helpen??
Advertisement
1 bericht
• Pagina 1 van 1
Wie is er online?
Gebruikers in dit forum: Geen geregistreerde gebruikers en 21 gasten