Advertisement
Guest User

Untitled

a guest
Jul 24th, 2014
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. #include <XBee.h>
  2.  
  3. // create the XBee object
  4. XBee xbee = XBee();
  5.  
  6. uint8_t payload[] = { 0, 0 };
  7.  
  8. // SH + SL Address of receiving XBee
  9. XBeeAddress64 addr64 = XBeeAddress64(0x0013a200, 0x408698be);
  10. ZBTxRequest zbTx = ZBTxRequest(addr64, payload, sizeof(payload));
  11. ZBTxStatusResponse txStatus = ZBTxStatusResponse();
  12.  
  13. int pin5 = 0;
  14.  
  15. void setup() {
  16. Serial.begin(9600);
  17. xbee.setSerial(Serial);
  18. }
  19.  
  20. void loop() {
  21. payload[0] = 0x34;
  22. payload[1] = 0x76;
  23.  
  24. if (digitalRead(7) == HIGH){
  25. xbee.send(zbTx);
  26. delay(1000);
  27. }
  28. }
  29.  
  30. #include <XBee.h>
  31.  
  32.  
  33. XBee xbee = XBee();
  34. XBeeResponse response = XBeeResponse();
  35. // create reusable response objects for responses we expect to handle
  36. ZBRxResponse rx = ZBRxResponse();
  37. ModemStatusResponse msr = ModemStatusResponse();
  38.  
  39.  
  40. void setup() {
  41. // start serial
  42. Serial.begin(9600);
  43. xbee.begin(Serial);
  44. }
  45.  
  46. // continuously reads packets, looking for ZB Receive or Modem Status
  47. void loop() {
  48. xbee.readPacket();
  49. if (xbee.getResponse().isAvailable()) {
  50. // got something
  51. if (xbee.getResponse().getApiId() == ZB_RX_RESPONSE) {
  52. // got a zb rx packet
  53. // now fill our zb rx class
  54. xbee.getResponse().getZBRxResponse(rx);
  55. // I check both bytes (or)
  56. if (rx.getData(0) == 0x34 || rx.getData(0) == 0x76 ) {
  57. digitalWrite(8, HIGH);
  58. }
  59. }
  60. }
  61. }
  62.  
  63. pinMode(8, OUTPUT);
  64.  
  65. pinMode(7, INPUT);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement