I am trying to use two XBee modules to send commands to the other arduino to do something.
The code I have (see code bellow) works and I wanted to use it so I can use the same keypad attached to my first arduino to control the other arduino to do exactly the same thing as the code shows.
I configured the two XBees (set the Pan ID same for both, Channel 11 for bought, Baud rate = 115200 for bought) and don't know what to do to the code. So I just uploaded it to both Arduinos but didn't work.
I matched the baud rate to my computer. the code has the serial print command.
I guess I am not understanding something. Any suggestion is helpful.
Here is the code
#include <Keypad.h>
const byte IOXpin = 2;
const byte ROWS = 4; // rows of the keypad
const byte COLS = 4; //columns of the kepad
char keys[ROWS][COLS] =
{
{ '1','2','3','A'},
{ '4','5','6','B' },
{ '7','8','9','C' },
{ '*','0','#', 'D' }
};
byte rowPins [ROWS] = { 3, 4, 5, 6};
byte colPins [COLS] = { 7, 8, 9,10 };
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup()
{
pinMode(IOXpin, OUTPUT);
digitalWrite(IOXpin, HIGH);
Serial.begin (115200);
}
void processNumber (const unsigned long amount)
{
Serial.print ("Dispensing ");
Serial.print (amount);
Serial.println (" uL.");
if (amount < 19 || amount > 300)
{
Serial.println ("Invalid Amount!!");
return;
}
unsigned long startTime = millis ();
unsigned long runTime = amount * 100; // assume 0.1 secs per uL
digitalWrite (IOXpin, LOW);
while (millis () - startTime < runTime)
{
if (kpd.getKey() == '*') // cancel button
{
Serial.println ("Cancelled.");
break;
}
} //
digitalWrite (IOXpin, HIGH);
Serial.println ("Done.");
}
void handleKeypress (const char key)
{
Serial.print ("Entered: ");
Serial.println (key);
static unsigned long receivedNumber = 0;
switch (key)
{
case '#':
processNumber (receivedNumber);
receivedNumber = 0;
break;
case '0' ... '9':
receivedNumber *= 10;
receivedNumber += key - '0';
break;
default:
Serial.println ("Unexpected input!");
break;
} // end of switch
} // end of handleKeypress
void loop()
{
byte key = kpd.getKey();
if (key)
handleKeypress (key);
}