Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Extremly low power 433MHz switch
- *
- * Button0: Turn off all lights(Switch A,B,D)
- * Button1: Turn on big light(Switch B)
- */
- #include <RCSwitch.h>
- #include <avr/sleep.h>
- #include <avr/wdt.h>
- // RCSwitch config
- int vccPin = 3;
- int dataPin = 4;
- char systemCode[6] = "01110";
- char switchA[6] = "10000";
- char switchB[6] = "01000";
- char switchC[6] = "00100";
- char switchD[6] = "00010";
- char switchE[6] = "00001";
- RCSwitch mySwitch = RCSwitch();
- // Switches
- int button0 = 0;
- int button1 = 1;
- void setup() {
- // Turn off interrupts
- cli();
- // Pin to turn on and of transmitter
- pinMode(vccPin, OUTPUT);
- digitalWrite(vccPin, LOW); // Turn off radio
- delay(500);
- // Buttons
- pinMode(button0, INPUT_PULLUP);
- pinMode(button1, INPUT_PULLUP);
- // RCSwitch
- mySwitch.enableTransmit(dataPin);
- // Energie sparen
- ADCSRA &= ~(1<<ADEN); //Deaktiviere ADC
- ACSR = (1<<ACD); //Deaktiviere Analog Comparator
- // Sleepmode: Power-Down
- set_sleep_mode(SLEEP_MODE_PWR_DOWN);
- // Interrupts
- GIMSK = (1 << PCIE); //Enable Pin Change Interrupts
- PCMSK = (1 << PCINT0) | (1 << PCINT1); // Enable pin0 and pin1 interrupts
- // Enable interrupts
- sei();
- }
- void loop() {
- executeCommand();
- powerDown();
- }
- void executeCommand() {
- // Button 1?
- if (digitalRead(button0) == LOW) {
- powerUpTransmitter();
- // Turn off all lights(Switch A,B,D)
- mySwitch.switchOff(systemCode, switchA);
- mySwitch.switchOff(systemCode, switchB);
- mySwitch.switchOff(systemCode, switchD);
- }
- // Button 2?
- else if(digitalRead(button1) == LOW) {
- powerUpTransmitter();
- // Turn on big light(Switch B)
- mySwitch.switchOn(systemCode, switchA);
- }
- }
- void powerUpTransmitter() {
- digitalWrite(vccPin, HIGH);
- // Wait for module to strart
- delay(20);
- }
- void powerDown() {
- GIMSK = (1 << PCIE); // Enable Pin Change Interrupts
- digitalWrite(vccPin, LOW); // Turn off transmitter
- sleep_mode();
- GIMSK &= ~(1 << PCIE); // Disable Pin Change Interrupts (Debounce button)
- }
- ISR (PCINT0_vect) //the PCINT0_vect vector is used to identify the pin change interrupt.
- {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement