Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2021
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.04 KB | None | 0 0
  1. //#define F_CPU 8000000
  2. #include <IRremote.h>
  3. #include "PinChangeInt.h"
  4.  
  5. int pin;
  6. int state;
  7. unsigned long lastmillis = 0;
  8. unsigned long lastmillis_wake = 0;
  9. int wTime;
  10. #define pinD2 2 //set all the pins as interrupts with the PinChangeInt library
  11. #define pinD4 4
  12. #define pinD5 5
  13. #define pinD6 6
  14. #define pinD7 7
  15. #define IND_LED 8
  16. #define pinD9 9
  17. #define pinD10 10
  18. #define pinD11 11
  19. #define pinD12 12
  20. #define pinD13 13
  21. #define pinA14 14
  22. #define pinA15 15
  23. #define pinA16 16
  24. #define pinA17 17
  25. #define pinA18 18
  26. #define pinA19 19
  27.  
  28. IRsend irsend;
  29.  
  30. void setup() {
  31. // Serial.begin(9600);
  32.  
  33. // OSCCAL = 0xC8;
  34.  
  35. for (int i = 0; i < 20; i++) { //set all pins high to reduce current consumption, and because they are needed high anyway.
  36. pinMode(i, INPUT_PULLUP);
  37. }
  38.  
  39. ADCSRA &= ~(1 << 7); //ADC is not needed, disable it to save power.
  40. MCUCR |= (3 << 5); //BOD disable - set both BODS and BODSE at the same time
  41. MCUCR = (MCUCR & ~(1 << 5)) | (1 << 6); //then set the BODS bit and clear the BODSE bit at the same time.
  42.  
  43. attachPinChangeInterrupt(pinD2, digitalInterrupt, FALLING);
  44. attachPinChangeInterrupt(pinD4, digitalInterrupt, FALLING);
  45. attachPinChangeInterrupt(pinD5, digitalInterrupt, FALLING);
  46. attachPinChangeInterrupt(pinD6, digitalInterrupt, FALLING);
  47. attachPinChangeInterrupt(pinD7, digitalInterrupt, FALLING);
  48. attachPinChangeInterrupt(pinD9, digitalInterrupt, FALLING);
  49. attachPinChangeInterrupt(pinD10, digitalInterrupt, FALLING);
  50. attachPinChangeInterrupt(pinD11, digitalInterrupt, FALLING);
  51. attachPinChangeInterrupt(pinD12, digitalInterrupt, FALLING);
  52. attachPinChangeInterrupt(pinD13, digitalInterrupt, FALLING);
  53. attachPinChangeInterrupt(pinA14, digitalInterrupt, FALLING);
  54. attachPinChangeInterrupt(pinA15, digitalInterrupt, FALLING);
  55. attachPinChangeInterrupt(pinA16, digitalInterrupt, FALLING);
  56. attachPinChangeInterrupt(pinA17, digitalInterrupt, FALLING);
  57. attachPinChangeInterrupt(pinA18, digitalInterrupt, FALLING);
  58. attachPinChangeInterrupt(pinA19, digitalInterrupt, FALLING);
  59.  
  60. pinMode(IND_LED, OUTPUT);
  61. }
  62. void digitalInterrupt() {
  63. (wTime++);
  64. }
  65. void loop() {
  66.  
  67. if (pin >= 19) { //iterate a pin each loop
  68. pin = 2;
  69. }
  70. else {
  71. pin++;
  72. }
  73. state = digitalRead(pin);
  74.  
  75. if (pin == 2 && !state) { //TV Channel Down
  76. irsend.sendNEC(0x20DF629D, 32);
  77. digitalWrite(IND_LED, HIGH);
  78. delay(100);
  79. }
  80. else if (pin == 4 && !state) { //TV Channel Up
  81. irsend.sendNEC(0x20DFA25D, 32);
  82. digitalWrite(IND_LED, HIGH);
  83. delay(100);
  84. }
  85. else if (pin == 5 && !state) { //Stereo Pwr
  86. irsend.sendNEC(0x7E8154AB, 32);
  87. digitalWrite(IND_LED, HIGH);
  88. delay(100);
  89. }
  90. else if (pin == 6 && !state) { //Stereo_DVD
  91. irsend.sendNEC(0x5EA100FE, 32);
  92. digitalWrite(IND_LED, HIGH);
  93. delay(100);
  94. }
  95. else if (pin == 7 && !state) { //Stereo_Vol_UP
  96. irsend.sendNEC(0x5EA158A7, 32);
  97. digitalWrite(IND_LED, HIGH);
  98. delay(100);
  99. }
  100. else if (pin == 9 && !state) { //Stereo Mute
  101. irsend.sendNEC(0x5EA138C7, 32);
  102. digitalWrite(IND_LED, HIGH);
  103. delay(100);
  104. }
  105. else if (pin == 10 && !state) { //Stereo_Input_Down
  106. irsend.sendNEC(0x5EA1C43A, 32);
  107. digitalWrite(IND_LED, HIGH);
  108. delay(100);
  109. }
  110. else if (pin == 11 && !state) { //TV_Vol_Up
  111. irsend.sendNEC(0x20DF12ED, 32);
  112. digitalWrite(IND_LED, HIGH);
  113. delay(100);
  114. }
  115. else if (pin == 12 && !state) { //TV_Vol_Down
  116. irsend.sendNEC(0x20DFE21D, 32);
  117. digitalWrite(IND_LED, HIGH);
  118. delay(100);
  119. }
  120. else if (pin == 13 && !state) { //Stereo_Input_Up
  121. irsend.sendNEC(0x5EA1F806, 32);
  122. digitalWrite(IND_LED, HIGH);
  123. delay(100);
  124. }
  125. else if (pin == 14 && !state) { //TV_Input
  126. irsend.sendNEC(0x20DFF40B, 32);
  127. digitalWrite(IND_LED, HIGH);
  128. delay(100);
  129. }
  130. else if (pin == 15 && !state) { //TV_Power
  131. irsend.sendNEC(0x20DF10EF, 32);
  132. digitalWrite(IND_LED, HIGH);
  133. delay(100);
  134. }
  135. else if (pin == 16 && !state) { //TV_HDMI
  136. irsend.sendNEC(0x20DF639C, 32);
  137. digitalWrite(IND_LED, HIGH);
  138. delay(100);
  139. }
  140. else if (pin == 17 && !state) { //Stereo_Vol_Down
  141. irsend.sendNEC(0x5EA1D827, 32);
  142. digitalWrite(IND_LED, HIGH);
  143. delay(100);
  144.  
  145. }
  146. else if (pin == 18 && !state) { //TV_Guide
  147. irsend.sendNEC(0x20DF38C7, 32);
  148. digitalWrite(IND_LED, HIGH);
  149. delay(100);
  150. }
  151. else if (pin == 19 && !state) { //TV_Mute
  152. irsend.sendNEC(0x20DF906F, 32);
  153. digitalWrite(IND_LED, HIGH);
  154. delay(100);
  155. }
  156.  
  157. if (millis() - lastmillis >= 100) {
  158. lastmillis = millis();
  159. digitalWrite(IND_LED, LOW);
  160. }
  161. if ((wTime > 0) && (millis() - lastmillis_wake >= 10000)) { //amount of time the controller wakes up after a button press
  162. lastmillis_wake = millis();
  163. (wTime = 0);
  164. }
  165.  
  166. if (!wTime) {
  167. digitalWrite(IND_LED, LOW); //make sure the LED is off
  168. //ENABLE SLEEP - this enables the sleep mode
  169. SMCR |= (1 << 2); //power down mode
  170. SMCR |= 1;//enable sleep
  171. __asm__ __volatile__("sleep");
  172. }
  173. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement