Advertisement
digigram

RF_Transmitter_85

Jun 23rd, 2014
507
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.55 KB | None | 0 0
  1. #include <VirtualWire.h>
  2. #include <avr/sleep.h>
  3. #include <avr/interrupt.h>
  4. #include <avr/power.h>
  5. #include <avr/io.h>
  6.  
  7. /*
  8. Written by DigiGram CC-BY-SA applies
  9. This code is provided as-is and I do not guarantee that it works
  10.  
  11. rf_sender
  12.  This sketch will send the code for toggling a specific light.
  13.  Connect rf module on pin 0 (5 on ATtiny85). Switch on pin 1 (6).
  14.  Some power saving fu thanx to Nick Gammon - www.gammon.com.au
  15.  Note that this remote is the definition of vulnerable to a replay attack
  16.  */
  17.  
  18. const int buttonPin = 1;
  19. const int ledPin = 2;
  20. int buttonState = 0;
  21.  
  22. void setup()
  23. {
  24.   // Initialize the IO and ISR
  25.   vw_set_tx_pin(0);
  26.   vw_setup(2000); // Bits per sec
  27.   pinMode(buttonPin, INPUT);
  28.   pinMode(ledPin, OUTPUT);
  29.   // disable ADC
  30.   //ADCSRA = 0;  
  31. }
  32.  
  33. void pinInterrupt(void)
  34. {
  35.   detachInterrupt(0);  
  36. }
  37.  
  38. void sleepNow(void)
  39. {
  40.   attachInterrupt(0, toggleMe, RISING);
  41.   delay(200);
  42.   set_sleep_mode (SLEEP_MODE_PWR_DOWN);  
  43.   sleep_enable();
  44.   sleep_mode();  //or sleep_mode()
  45.   sleep_disable();
  46. }
  47.  
  48. void send (char *message)
  49. {
  50.   vw_send((uint8_t *)message, strlen(message));
  51.   vw_wait_tx(); // Wait until the whole message is gone
  52. }
  53.  
  54. void toggleMe(void)
  55. {
  56.     send("L01");
  57.     digitalWrite(ledPin, HIGH);
  58.     delay(100);
  59.     digitalWrite(ledPin, LOW);
  60.     delay(200);
  61.     digitalWrite(ledPin, HIGH);
  62.     delay(200);
  63.     digitalWrite(ledPin, LOW);
  64.     delay(200);
  65.     digitalWrite(ledPin, HIGH);
  66.     delay(100);
  67.     digitalWrite(ledPin, LOW);  
  68. }
  69.  
  70. void loop()
  71. {
  72.   sleepNow();
  73.   toggleMe();
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement