Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //#define F_CPU 8000000
- #include <IRremote.h>
- #include "PinChangeInt.h"
- int pin;
- int state;
- unsigned long lastmillis = 0;
- unsigned long lastmillis_wake = 0;
- int wTime;
- #define pinD2 2 //set all the pins as interrupts with the PinChangeInt library
- #define pinD4 4
- #define pinD5 5
- #define pinD6 6
- #define pinD7 7
- #define IND_LED 8
- #define pinD9 9
- #define pinD10 10
- #define pinD11 11
- #define pinD12 12
- #define pinD13 13
- #define pinA14 14
- #define pinA15 15
- #define pinA16 16
- #define pinA17 17
- #define pinA18 18
- #define pinA19 19
- IRsend irsend;
- void setup() {
- // Serial.begin(9600);
- // OSCCAL = 0xC8;
- for (int i = 0; i < 20; i++) { //set all pins high to reduce current consumption, and because they are needed high anyway.
- pinMode(i, INPUT_PULLUP);
- }
- ADCSRA &= ~(1 << 7); //ADC is not needed, disable it to save power.
- MCUCR |= (3 << 5); //BOD disable - set both BODS and BODSE at the same time
- MCUCR = (MCUCR & ~(1 << 5)) | (1 << 6); //then set the BODS bit and clear the BODSE bit at the same time.
- attachPinChangeInterrupt(pinD2, digitalInterrupt, FALLING);
- attachPinChangeInterrupt(pinD4, digitalInterrupt, FALLING);
- attachPinChangeInterrupt(pinD5, digitalInterrupt, FALLING);
- attachPinChangeInterrupt(pinD6, digitalInterrupt, FALLING);
- attachPinChangeInterrupt(pinD7, digitalInterrupt, FALLING);
- attachPinChangeInterrupt(pinD9, digitalInterrupt, FALLING);
- attachPinChangeInterrupt(pinD10, digitalInterrupt, FALLING);
- attachPinChangeInterrupt(pinD11, digitalInterrupt, FALLING);
- attachPinChangeInterrupt(pinD12, digitalInterrupt, FALLING);
- attachPinChangeInterrupt(pinD13, digitalInterrupt, FALLING);
- attachPinChangeInterrupt(pinA14, digitalInterrupt, FALLING);
- attachPinChangeInterrupt(pinA15, digitalInterrupt, FALLING);
- attachPinChangeInterrupt(pinA16, digitalInterrupt, FALLING);
- attachPinChangeInterrupt(pinA17, digitalInterrupt, FALLING);
- attachPinChangeInterrupt(pinA18, digitalInterrupt, FALLING);
- attachPinChangeInterrupt(pinA19, digitalInterrupt, FALLING);
- pinMode(IND_LED, OUTPUT);
- }
- void digitalInterrupt() {
- (wTime++);
- }
- void loop() {
- if (pin >= 19) { //iterate a pin each loop
- pin = 2;
- }
- else {
- pin++;
- }
- state = digitalRead(pin);
- if (pin == 2 && !state) { //TV Channel Down
- irsend.sendNEC(0x20DF629D, 32);
- digitalWrite(IND_LED, HIGH);
- delay(100);
- }
- else if (pin == 4 && !state) { //TV Channel Up
- irsend.sendNEC(0x20DFA25D, 32);
- digitalWrite(IND_LED, HIGH);
- delay(100);
- }
- else if (pin == 5 && !state) { //Stereo Pwr
- irsend.sendNEC(0x7E8154AB, 32);
- digitalWrite(IND_LED, HIGH);
- delay(100);
- }
- else if (pin == 6 && !state) { //Stereo_DVD
- irsend.sendNEC(0x5EA100FE, 32);
- digitalWrite(IND_LED, HIGH);
- delay(100);
- }
- else if (pin == 7 && !state) { //Stereo_Vol_UP
- irsend.sendNEC(0x5EA158A7, 32);
- digitalWrite(IND_LED, HIGH);
- delay(100);
- }
- else if (pin == 9 && !state) { //Stereo Mute
- irsend.sendNEC(0x5EA138C7, 32);
- digitalWrite(IND_LED, HIGH);
- delay(100);
- }
- else if (pin == 10 && !state) { //Stereo_Input_Down
- irsend.sendNEC(0x5EA1C43A, 32);
- digitalWrite(IND_LED, HIGH);
- delay(100);
- }
- else if (pin == 11 && !state) { //TV_Vol_Up
- irsend.sendNEC(0x20DF12ED, 32);
- digitalWrite(IND_LED, HIGH);
- delay(100);
- }
- else if (pin == 12 && !state) { //TV_Vol_Down
- irsend.sendNEC(0x20DFE21D, 32);
- digitalWrite(IND_LED, HIGH);
- delay(100);
- }
- else if (pin == 13 && !state) { //Stereo_Input_Up
- irsend.sendNEC(0x5EA1F806, 32);
- digitalWrite(IND_LED, HIGH);
- delay(100);
- }
- else if (pin == 14 && !state) { //TV_Input
- irsend.sendNEC(0x20DFF40B, 32);
- digitalWrite(IND_LED, HIGH);
- delay(100);
- }
- else if (pin == 15 && !state) { //TV_Power
- irsend.sendNEC(0x20DF10EF, 32);
- digitalWrite(IND_LED, HIGH);
- delay(100);
- }
- else if (pin == 16 && !state) { //TV_HDMI
- irsend.sendNEC(0x20DF639C, 32);
- digitalWrite(IND_LED, HIGH);
- delay(100);
- }
- else if (pin == 17 && !state) { //Stereo_Vol_Down
- irsend.sendNEC(0x5EA1D827, 32);
- digitalWrite(IND_LED, HIGH);
- delay(100);
- }
- else if (pin == 18 && !state) { //TV_Guide
- irsend.sendNEC(0x20DF38C7, 32);
- digitalWrite(IND_LED, HIGH);
- delay(100);
- }
- else if (pin == 19 && !state) { //TV_Mute
- irsend.sendNEC(0x20DF906F, 32);
- digitalWrite(IND_LED, HIGH);
- delay(100);
- }
- if (millis() - lastmillis >= 100) {
- lastmillis = millis();
- digitalWrite(IND_LED, LOW);
- }
- if ((wTime > 0) && (millis() - lastmillis_wake >= 10000)) { //amount of time the controller wakes up after a button press
- lastmillis_wake = millis();
- (wTime = 0);
- }
- if (!wTime) {
- digitalWrite(IND_LED, LOW); //make sure the LED is off
- //ENABLE SLEEP - this enables the sleep mode
- SMCR |= (1 << 2); //power down mode
- SMCR |= 1;//enable sleep
- __asm__ __volatile__("sleep");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement