zykes

Untitled

May 7th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. #include <Arduino.h>
  2.  
  3. #define PJON_INCLUDE_TS true
  4. //#define PJON_INCLUDE_ETHERNET false
  5. #include <PJON.h>
  6.  
  7. #include "AltSoftSerial.h"
  8.  
  9. // <Strategy name> bus(selected device id)
  10. PJON<ThroughSerial> bus(2);
  11.  
  12. AltSoftSerial serial;
  13.  
  14. void receiver_function(uint8_t *payload, uint16_t length, const PJON_Packet_Info &packet_info) {
  15. /* Make use of the payload before sending something, the buffer where payload points to is
  16. overwritten when a new message is dispatched */
  17. Serial.println("RECEIVED");
  18.  
  19. if(payload[0] == 'B') {
  20. digitalWrite(13, HIGH);
  21. delay(30);
  22. digitalWrite(13, LOW);
  23. }
  24. };
  25.  
  26. void setup() {
  27. Serial.begin(9600);
  28. Serial.println("STARTING");
  29.  
  30. pinMode(13, OUTPUT);
  31. digitalWrite(13, LOW); // Initialize LED 13 to be off
  32.  
  33. serial.begin(9600);
  34.  
  35. bus.begin();
  36. bus.set_receiver(receiver_function);
  37.  
  38. bus.strategy.set_serial(&serial);
  39. };
  40.  
  41.  
  42. void loop() {
  43. bus.receive(1000);
  44. //bus.send(1, "B", 1);
  45. //delay(1000);
  46. };
Advertisement
Add Comment
Please, Sign In to add comment