Created
November 1, 2018 16:12
-
-
Save bseishen/e718a38ba81b5f9ffc2abfd71c1c6078 to your computer and use it in GitHub Desktop.
Vizio Auto Sleep
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Takes any remote press and sets a 1hr timer. | |
* Timer is constantly reset if a button is pressed. | |
* After the Timer has elapsed, sleep timer is set to 30min on the Vizio TV. | |
*/ | |
#include <IRremote.h> | |
//VIZIO TV COMMANDS | |
#define MENU 0x20DFF20D | |
#define UP 0x20DFA25D | |
#define DOWN 0x20DF629D | |
#define OK 0x20DF22DD | |
#define BACK 0x20DF52AD | |
#define PWR 0x20DF10EF | |
#define END 0x00000000 //USED to terminated the command array. | |
#define TIMESPAN 3600000 //ONE HOUR | |
int RECV_PIN = 11; | |
IRrecv irrecv(RECV_PIN); | |
IRsend irsend; | |
decode_results results; | |
unsigned long timestamp; | |
bool isEnabled = false; | |
//Set Sleep timer to 30min | |
uint32_t sendArray[] = {MENU, UP, UP, UP, UP, UP, UP, DOWN, DOWN, DOWN, OK, UP, UP, UP, DOWN, OK, DOWN, DOWN, DOWN, DOWN, DOWN, DOWN, UP, UP, UP, UP, OK, BACK, BACK, END}; | |
void sendSleepSignal(){ | |
uint8_t i = 0; | |
while(sendArray[i] != 0){ | |
irsend.sendNEC(sendArray[i], 32); | |
i++; | |
delay(500); | |
Serial.println(i); | |
} | |
} | |
void setup() | |
{ | |
Serial.begin(9600); | |
irrecv.enableIRIn(); // Start the receiver | |
timestamp = millis(); | |
} | |
void loop() { | |
//Anytime a code is received, set the timeout two hours in the future. | |
if (irrecv.decode(&results)) { | |
Serial.println(results.value, HEX); | |
timestamp = millis(); | |
isEnabled = true; | |
irrecv.resume(); // Receive the next value | |
} | |
//Timeout has expired | |
if((millis() - timestamp > TIMESPAN) && isEnabled == true){ | |
Serial.println("TimerExpired!"); | |
sendSleepSignal(); | |
irrecv.enableIRIn(); | |
isEnabled = false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment