Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <VirtualWire.h>
- #include <avr/sleep.h>
- #include <avr/interrupt.h>
- #include <avr/power.h>
- #include <avr/io.h>
- /*
- Written by DigiGram CC-BY-SA applies
- This code is provided as-is and I do not guarantee that it works
- rf_sender
- This sketch will send the code for toggling a specific light.
- Connect rf module on pin 0 (5 on ATtiny85). Switch on pin 1 (6).
- Some power saving fu thanx to Nick Gammon - www.gammon.com.au
- Note that this remote is the definition of vulnerable to a replay attack
- */
- const int buttonPin = 1;
- const int ledPin = 2;
- int buttonState = 0;
- void setup()
- {
- // Initialize the IO and ISR
- vw_set_tx_pin(0);
- vw_setup(2000); // Bits per sec
- pinMode(buttonPin, INPUT);
- pinMode(ledPin, OUTPUT);
- // disable ADC
- //ADCSRA = 0;
- }
- void pinInterrupt(void)
- {
- detachInterrupt(0);
- }
- void sleepNow(void)
- {
- attachInterrupt(0, toggleMe, RISING);
- delay(200);
- set_sleep_mode (SLEEP_MODE_PWR_DOWN);
- sleep_enable();
- sleep_mode(); //or sleep_mode()
- sleep_disable();
- }
- void send (char *message)
- {
- vw_send((uint8_t *)message, strlen(message));
- vw_wait_tx(); // Wait until the whole message is gone
- }
- void toggleMe(void)
- {
- send("L01");
- digitalWrite(ledPin, HIGH);
- delay(100);
- digitalWrite(ledPin, LOW);
- delay(200);
- digitalWrite(ledPin, HIGH);
- delay(200);
- digitalWrite(ledPin, LOW);
- delay(200);
- digitalWrite(ledPin, HIGH);
- delay(100);
- digitalWrite(ledPin, LOW);
- }
- void loop()
- {
- sleepNow();
- toggleMe();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement