system
May 15, 2012, 2:51pm
#1
Hi all,
I have a problem with my XBee's, let me explain:
On Module 1, I have 2 buttons, each button corresponds to a letter to be sent
On Module 2, I 2 LEDs
If I press the button 1, 'a' is sent, the LED goes on great
If I press the button 2, 'b' is sent, the LED does not light up ....
But I press the two buttons at the same time, the Leds is ON but flashing.....
Anyone have a clue how I could fix this??
Thank you
system
May 15, 2012, 3:19pm
#2
I have a problem with my XBee's
Sure do. Not enough information.
What kind of XBees? How are they configured? What are they attached to?
On Module 1, I have 2 buttons, each button corresponds to a letter to be sent
Switches would probably work better.
system
May 15, 2012, 4:28pm
#3
My Xbee are S2, first is coordinator AT and second is router AT
Sorry, yes they are switch
system
May 15, 2012, 4:30pm
#4
Module 1
int BUTD = 2; //attribute une patte à un bouton
int BUTH = 3;
int BUTB = 4;
int BUTG = 5;
int val = 0;
byte val2 = 0;
void setup(){
pinMode(BUTD, INPUT); //déclare le type entrée ou sortie
pinMode(BUTH, INPUT);
pinMode(BUTB, INPUT);
pinMode(BUTG, INPUT);
Serial.begin(9600);
}
void loop(){
val = analogRead(A0); //lit la valeur du potentiomètre
val2 =map(val, 0, 1023, 0, 255); //change le code de l'information de int en byte
if(val2 >= 10 && val2 < 92){ //1ère vitesse + direction
if(digitalRead(BUTH) == HIGH){
Serial.print('A');
delay(10);
}
if(digitalRead(BUTB) == HIGH){
Serial.print('B');
delay(10);
}
if(digitalRead(BUTD) == HIGH){
Serial.print('C');
delay(10);
}
if(digitalRead(BUTG) == HIGH){
Serial.print('D');
delay(10);
}
}
if(val2 >= 92 && val2 < 174){ //2ème vitesse + direction
if(digitalRead(BUTH) == HIGH){
Serial.print('E');
delay(10);
}
if(digitalRead(BUTB) == HIGH){
Serial.print('F');
delay(10);
}
if(digitalRead(BUTD) == HIGH){
Serial.print('G');
delay(10);
}
if(digitalRead(BUTG) == HIGH){
Serial.print('H');
delay(10);
}
}
if(val2 >= 174 && val2 < 255){ //3ème vitesse + direction
if(digitalRead(BUTH) == HIGH){
Serial.print('I');
delay(10);
}
if(digitalRead(BUTB) == HIGH){
Serial.print('J');
delay(10);
}
if(digitalRead(BUTD) == HIGH){
Serial.print('K');
delay(10);
}
if(digitalRead(BUTG) == HIGH){
Serial.print('L');
delay(10);
}
}
}
Module 2
int Led = 2;
int Le = 4;
void setup(){
Serial.begin(9600);
pinMode(Led, OUTPUT);
pinMode(Le, OUTPUT);
}
void loop(){
if(Serial.available() > 0){
if(Serial.read() == 'A'){
digitalWrite(Led, HIGH);
delay (10);
digitalWrite(Led, LOW);
}
if(Serial.read() == 'B'){
digitalWrite(Le, HIGH);
delay (10);
digitalWrite(Le, LOW);
}
}
system
May 15, 2012, 7:06pm
#5
You send a letter. Let's say it's a 'C'.
There is a character to read. You read that letter. It's not an 'A', so you read another letter (oops). That's not a 'B', so you read another letter (double oops). You really need to compare the SAME letter to 'B', 'C', 'D', etc. That means, of course, that you need to save the letter.