Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Arduino Wireless Communication Tutorial
- * Example 1 - Receiver Code
- *
- * by Dejan Nedelkovski, www.HowToMechatronics.com
- *
- * Library: TMRh20/RF24, https://github.com/tmrh20/RF24/
- */
- #include <Wire.h>
- #include "RTClib.h"
- RTC_DS3231 rtc;
- #include <SPI.h>
- #include <nRF24L01.h>
- #include <RF24.h>
- RF24 radio(48,49); // CE, CSN
- const byte addresses[][6] = {"00001", "00002"};
- int prijato=0;
- int teplota;
- int vlhkost;
- void setup() {
- Serial.begin(9600);
- rtc.begin();
- rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
- radio.begin();
- radio.openReadingPipe(1, addresses[1]);
- radio.setPALevel(RF24_PA_MAX);
- radio.startListening();
- }
- void loop() {
- if (radio.available())
- {
- radio.read(&prijato, sizeof(prijato));
- Serial.print("prijata data: ");
- Serial.println(prijato);
- DateTime now = rtc.now();
- Serial.print(now.hour(), DEC);
- Serial.print(':');
- Serial.print(now.minute(), DEC);
- Serial.print(':');
- Serial.print(now.second(), DEC);
- Serial.println(" ");
- switch(prijato)
- {
- case 1010: //teplota
- radio.read(&teplota, sizeof(teplota));
- Serial.print("teplota: ");
- Serial.print(teplota);
- Serial.println("°C");
- break;
- case 1011: //vlhkost
- radio.read(&vlhkost, sizeof(vlhkost));
- Serial.print("vlhkost: ");
- Serial.print(vlhkost);
- Serial.println("%");
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement