Advertisement
Guest User

Untitled

a guest
Apr 19th, 2020
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.68 KB | None | 0 0
  1. #include "Arduino.h"
  2. #include <RFM69.h>
  3. #include <SPI.h>
  4. #include <SPIFlash.h>
  5.  
  6.  
  7.  
  8. #define MYNODEID      1
  9. #define LED           0
  10. #define TONODEID      2
  11. #define FREQUENCY   RF69_433MHZ
  12. #define NETWORKID     0
  13.  
  14. RFM69 radio;
  15.  
  16. void setup() {
  17.  
  18. Serial.begin(9600);
  19. delay(8000);
  20. Serial.print(F("Node "));
  21. Serial.print(MYNODEID,DEC);
  22. Serial.println(F(" ready"));
  23. pinMode(LED, OUTPUT);
  24. radio.initialize(FREQUENCY, MYNODEID, NETWORKID);
  25. radio.setHighPower(true);
  26. }
  27.  
  28. void loop() {
  29.  
  30.   static char sendbuffer[62];
  31.   static int sendlength = 0;
  32.   char input = Serial.read();
  33.  
  34.       if (input != '\r') // not a carriage return checkt, dass nicht ohne Inhalt nur bei enter gesendet wird
  35.       {
  36.         sendbuffer[sendlength] = input;
  37.         sendlength++;
  38.       }
  39.  
  40.       // If the input is a carriage return, or the buffer is full:
  41.  
  42.       if ((input == '\r') || (sendlength == 61)) // CR or buffer full
  43.       {
  44.       Serial.print(F("sending to node "));
  45.       Serial.print(TONODEID, DEC);
  46.       Serial.print(F(", message ["));
  47.       for (byte i = 0; i < sendlength; i++) // was im buffer steht Hello World
  48.         Serial.print(sendbuffer[i]);
  49.       Serial.println(F("]"));
  50.       sendlength = 0; // reset the packet
  51.       digitalWrite(LED,HIGH);
  52.       Serial.println("LED on");
  53.       delay(1000);
  54.       digitalWrite(LED,LOW);
  55.       Serial.println("LED off");
  56.       delay(1000);
  57.       digitalWrite(LED,HIGH);
  58.       Serial.println("LED ON");
  59.       delay(500);
  60.       digitalWrite(LED,LOW);
  61.       Serial.println("LED OFF");
  62.       delay(500);
  63.       radio.send(TONODEID, sendbuffer, sendlength);
  64. //      Serial.println(F("Cycle completed"));
  65. //      delay(500);
  66.  
  67.   }
  68.  
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement