Skip to content

Commit

Permalink
Added SendAndReceive example
Browse files Browse the repository at this point in the history
  • Loading branch information
gioblu committed May 1, 2016
1 parent 208c4b7 commit 2a7a357
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
28 changes: 28 additions & 0 deletions examples/SendAndReceive/Device1/Device1.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <PJON.h>

// bus(Arduino pin used, selected device id)
PJON bus(12, 44);

void setup() {
pinModeFast(13, OUTPUT);
digitalWriteFast(13, LOW); // Initialize LED 13 to be off
bus.begin(); // Initialize PJON bus

bus.set_receiver(receiver_function);
bus.send(45, "B", 1);
Serial.begin(115200);
};

void receiver_function(uint8_t length, uint8_t *payload) {
if((char)payload[0] == 'B') {
bus.send(45, "B", 1);
digitalWrite(13, HIGH);
delay(15);
digitalWrite(13, LOW);
}
}

void loop() {
bus.receive(1000);
bus.update();
};
28 changes: 28 additions & 0 deletions examples/SendAndReceive/Device2/Device2.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <PJON.h>

// bus(Arduino pin used, selected device id)
PJON bus(12, 45);

void setup() {
pinModeFast(13, OUTPUT);
digitalWriteFast(13, LOW); // Initialize LED 13 to be off
bus.begin(); // Initialize PJON bus

bus.set_receiver(receiver_function);
bus.send(44, "B", 1);
Serial.begin(115200);
};

void receiver_function(uint8_t length, uint8_t *payload) {
if((char)payload[0] == 'B') {
bus.send(44, "B", 1);
digitalWrite(13, HIGH);
delay(15);
digitalWrite(13, LOW);
}
}

void loop() {
bus.receive(1000);
bus.update();
};

0 comments on commit 2a7a357

Please sign in to comment.