Skip to content

Commit

Permalink
Follow TV power to trigger IR codes
Browse files Browse the repository at this point in the history
  • Loading branch information
brunodmt committed May 8, 2023
1 parent f96b7af commit 24ab963
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions ir_tv_follower/ir_tv_follower.ino
Expand Up @@ -11,6 +11,9 @@ const size_t kEepromSize = 8;
// Address to store the IR code, const as we only need one value
const int kIrCodeAddr = 0;

// USB treshsold to trigger a code and turn off the device
const float kUsbVTresh = 1;

// Default delay to use in most cases
const uint32_t kDelayMs = 100;
// IR Receiver Pin
Expand All @@ -29,6 +32,9 @@ uint64_t temp_code;
// Result struct to receive decoding from IRremote
decode_results ir_results;

// Current USB Voltage
float usb_voltage;

// Programming mode to register a new code
void program_mode() {
// Turn on the screen
Expand Down Expand Up @@ -110,6 +116,8 @@ void setup() {
irrecv.enableIRIn();
// Read the IR code from EEPROM
ir_code = EEPROM.readULong64(kIrCodeAddr);
// Send a code when turning on, as this will be triggered by the TV turning on
irsend.sendNEC(ir_code);
}

void loop() {
Expand All @@ -124,5 +132,15 @@ void loop() {
program_mode();
}

// Get updated USB voltage
usb_voltage = M5.Axp.GetVBusVoltage();
// If it went below the treshold
if (usb_voltage < kUsbVTresh) {
// Send a code to turn the speakers off
irsend.sendNEC(ir_code);
// and turn off itself
M5.Axp.PowerOff();
}

delay(kDelayMs);
}

0 comments on commit 24ab963

Please sign in to comment.