Advertisement
Guest User

Attiny85 pin change interrupt problem

a guest
Apr 11th, 2014
722
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.00 KB | None | 0 0
  1. /**
  2.  * Extremly low power 433MHz switch
  3.  *
  4.  * Button0: Turn off all lights(Switch A,B,D)
  5.  * Button1: Turn on big light(Switch B)
  6.  */
  7. #include <RCSwitch.h>
  8. #include <avr/sleep.h>
  9. #include <avr/wdt.h>
  10.  
  11. // RCSwitch config
  12. int dataPin = 4;
  13. int vccPin = 3;
  14. char systemCode[6] = "01110";
  15. char switchA[6] = "10000";
  16. char switchB[6] = "01000";
  17. char switchC[6] = "00100";
  18. char switchD[6] = "00010";
  19. char switchE[6] = "00001";
  20. RCSwitch mySwitch = RCSwitch();
  21.  
  22. void setup() {                
  23.   // Turn off interrupts
  24.   cli();
  25.   // Pin to turn on and of transmitter
  26.   pinMode(vccPin, OUTPUT);
  27.   digitalWrite(vccPin, LOW); // Turn off radio    
  28.  
  29.   // RCSwitch
  30.   mySwitch.enableTransmit(dataPin);
  31.  
  32.   // Safe energy
  33.   ADCSRA &= ~(1<<ADEN); //Deactivate ADC
  34.   ACSR = (1<<ACD); // Deactivate Analog Comparator
  35.  
  36.   // Sleepmode: Power-Down
  37.   set_sleep_mode(SLEEP_MODE_PWR_DOWN);
  38.  
  39.   // Interrupts  
  40.   GIMSK = (1 << PCIE);  //Enable Pin Change Interrupts
  41.   PCMSK = (1 << PCINT0) | (1 << PCINT1); // Enable pin0 and pin1 interrupts
  42.   // Enable interrupts
  43.   sei();
  44. }
  45.  
  46. void loop() {
  47.   executeCommand();
  48.   powerDown();
  49. }
  50.  
  51. void executeCommand() {
  52.   // Button 1?
  53.   if (PINB & (1 << PCINT0)) {
  54.     powerUpTransmitter();
  55.     // Turn off all lights(Switch A,B,D)
  56.     mySwitch.switchOff(systemCode, switchA);
  57.     mySwitch.switchOff(systemCode, switchB);
  58.     mySwitch.switchOff(systemCode, switchD);
  59.   }
  60.   // Button 2?
  61.   else if(PINB & (1 << PCINT1)) {
  62.     powerUpTransmitter();
  63.     // Turn on big light(Switch B)
  64.     mySwitch.switchOn(systemCode, switchA);
  65.   }
  66. }
  67.  
  68. void powerUpTransmitter() {
  69.   digitalWrite(vccPin, HIGH);
  70.   // Wait for module to strart
  71.   delay(20);
  72. }
  73.  
  74. void powerDown() {
  75.   GIMSK |= (1 << PCIE);       //Enable Pin Change Interrupts
  76.   digitalWrite(vccPin, LOW);  // Turn off transmitter
  77.   sleep_mode();
  78.  
  79.   GIMSK &= ~(1 << PCIE);  //Disable Pin Change Interrupts
  80. }
  81.  
  82. ISR (PCINT0_vect)       //the PCINT0_vect vector is used to identify the pin change interrupt.
  83. {
  84.    
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement