Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SPI.h>
- #include "nRF24L01.h"
- #include "RF24.h"
- #include <avr/sleep.h>
- #include <avr/power.h>
- #define REED_SWITCH 2
- RF24 radio(7,8); // CE, CSN
- const uint64_t pipes[1] = { 0xCAFECAFEA1LL };
- // Payload
- char send_payload[] = "MAIL";
- uint8_t send_payload_size = strlen(send_payload);
- void pin2Interrupt(void)
- {
- /* This will bring us back from sleep. */
- }
- void enterSleep(void) {
- /* Setup pin2 as an interrupt and attach handler. */
- delay(100);
- set_sleep_mode(SLEEP_MODE_PWR_DOWN);
- sleep_enable();
- sleep_mode();
- /* The program will continue from here. */
- /* First thing to do is disable sleep. */
- sleep_disable();
- }
- void setup(void)
- {
- pinMode(REED_SWITCH, INPUT_PULLUP);
- attachInterrupt(0, pin2Interrupt, FALLING);
- Serial.begin(9600);
- radio.begin();
- radio.setPALevel(RF24_PA_MAX);
- radio.setDataRate(RF24_250KBPS);
- radio.enableDynamicPayloads();
- radio.setRetries(5,15); // delay (multiple of 250ns) and # of retries
- radio.openWritingPipe(pipes[0]);
- }
- void loop(void)
- {
- enterSleep();
- radio.powerUp();
- radio.write( send_payload, send_payload_size );
- radio.powerDown();
- }
- // vim:cin:ai:sts=2 sw=2 ft=cpp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement