Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Arduino Wireless Communication Tutorial
- * Example 1 - Transmitter Code
- *
- * by Dejan Nedelkovski, www.HowToMechatronics.com
- *
- * Library: TMRh20/RF24, https://github.com/tmrh20/RF24/
- */
- #include <SPI.h>
- #include <nRF24L01.h>
- #include <RF24.h>
- #define TRANSMIT_INTERVAL_MS 1000
- #define MESSAGE_KEY 12345
- typedef enum {
- SENSOR_TEMP = 0,
- SENSOR_PRESS
- } sensor_type_t;
- typedef struct {
- int key;
- sensor_type_t type;
- int val;
- } sensor_data_t;
- RF24 radio(9, 10); // CE, CSN
- const byte address[6] = "00001";
- void setup() {
- Serial.begin(9600);
- radio.begin();
- radio.openWritingPipe(address);
- radio.setPALevel(RF24_PA_MIN);
- radio.stopListening();
- }
- void loop() {
- sensor_data_t msg;
- msg.key = MESSAGE_KEY;
- msg.type = SENSOR_TEMP;
- msg.val = 123;
- radio.write(&msg, sizeof(sensor_data_t));
- delay(TRANSMIT_INTERVAL_MS);
- Serial.println(" TX done!\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement