Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <RFM69.h>
- #include <SPI.h>
- #define NETWORKID 100
- #define NODEID 3
- #define RECEIVER 1
- #define FREQUENCY RF69_868MHZ
- #define ENCRYPTKEY "drapeauarbitrage"
- #define IS_RFM69HCW true
- #define RFM69_CS 8
- #define RFM69_IRQ 7
- #define RFM69_IRQN 4
- #define RFM69_RST 4
- #define SERIAL_BAUD 115200
- #define LED 13 // onboard blinky
- const uint8_t g_PinButton = 13;
- RFM69 g_Radio = RFM69(RFM69_CS, RFM69_IRQ, IS_RFM69HCW, RFM69_IRQN);
- void setup() {
- pinMode(RFM69_RST, OUTPUT);
- digitalWrite(RFM69_RST, HIGH);
- delay(100);
- digitalWrite(RFM69_RST, LOW);
- delay(100);
- g_Radio.initialize(FREQUENCY, NODEID, NETWORKID);
- if (IS_RFM69HCW) {
- g_Radio.setHighPower();
- }
- g_Radio.setPowerLevel(31); // power output ranges from 0 (5dBm) to 31 (20dBm)
- g_Radio.encrypt(ENCRYPTKEY);
- pinMode(LED, OUTPUT);
- pinMode(g_PinButton, INPUT);
- }
- void loop() {
- bool ButtonPressed = digitalRead(g_PinButton);
- bool ButtonPressed_RadioPacket = true;
- if (ButtonPressed) {
- size_t BooleanSize = sizeof(bool);
- if (g_Radio.sendWithRetry(RECEIVER, (const void*)(&ButtonPressed_RadioPacket), BooleanSize)) {
- Blink(LED, 50, 3);
- }
- g_Radio.receiveDone(); //put g_Radio in RX mode
- }
- }
- void Blink(uint8_t pin, unsigned long delay_ms, unsigned loops)
- {
- bool State = HIGH;
- for (unsigned i = 0u; i < loops; ++i) {
- digitalWrite(pin, State);
- delay(delay_ms);
- State = !State;
- }
- }
Add Comment
Please, Sign In to add comment