Advertisement
Guest User

Arduino_Mailbox_Emitter

a guest
Mar 22nd, 2015
355
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.21 KB | None | 0 0
  1. #include <SPI.h>
  2. #include "nRF24L01.h"
  3. #include "RF24.h"
  4.  
  5. #include <avr/sleep.h>
  6. #include <avr/power.h>
  7.  
  8. #define REED_SWITCH 2
  9.  
  10. RF24 radio(7,8); // CE, CSN
  11.  
  12. const uint64_t pipes[1] = { 0xCAFECAFEA1LL };
  13.  
  14. // Payload
  15. char send_payload[] = "MAIL";
  16. uint8_t send_payload_size = strlen(send_payload);
  17.  
  18. void pin2Interrupt(void)
  19. {
  20.   /* This will bring us back from sleep. */
  21. }
  22.  
  23. void enterSleep(void) {
  24.   /* Setup pin2 as an interrupt and attach handler. */
  25.   delay(100);
  26.   set_sleep_mode(SLEEP_MODE_PWR_DOWN);
  27.   sleep_enable();
  28.   sleep_mode();
  29.  
  30.   /* The program will continue from here. */
  31.   /* First thing to do is disable sleep. */
  32.   sleep_disable();
  33. }
  34.  
  35. void setup(void)
  36. {
  37.   pinMode(REED_SWITCH, INPUT_PULLUP);  
  38.   attachInterrupt(0, pin2Interrupt, FALLING);
  39.  
  40.   Serial.begin(9600);
  41.  
  42.   radio.begin();
  43.   radio.setPALevel(RF24_PA_MAX);
  44.   radio.setDataRate(RF24_250KBPS);
  45.   radio.enableDynamicPayloads();
  46.   radio.setRetries(5,15); // delay (multiple of 250ns) and # of retries
  47.   radio.openWritingPipe(pipes[0]);
  48. }
  49.  
  50. void loop(void)
  51. {
  52.     enterSleep();
  53.    
  54.     radio.powerUp();
  55.     radio.write( send_payload, send_payload_size );
  56.     radio.powerDown();
  57. }
  58. // vim:cin:ai:sts=2 sw=2 ft=cpp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement