Skip to content

Instantly share code, notes, and snippets.

@hollyhockberry
Created October 25, 2021 12:30
Show Gist options
  • Save hollyhockberry/0cb2f407dfbfaad9db0db06b4ac67bea to your computer and use it in GitHub Desktop.
Save hollyhockberry/0cb2f407dfbfaad9db0db06b4ac67bea to your computer and use it in GitHub Desktop.
FADER Unit and IR Unit on single task
#include <Arduino.h>
#include <IRsend.h>
static IRsend irsend(26);
static constexpr int input_pin = 13;
void setup() {
irsend.begin();
}
void loop() {
static int targetVolume = 0;
static int currentVolume = targetVolume;
const auto v = ::analogRead(input_pin);
if (v <= 0) {
targetVolume = 0;
} else if (v >= 4096) {
targetVolume = 4;
} else {
targetVolume = static_cast<int>(v / 1365) + 1;
}
if (targetVolume == currentVolume) {
return;
}
const auto sign = targetVolume > currentVolume ? 1 : -1;
if (sign > 0) {
irsend.sendNEC(0x41B65DA2, 32);
} else {
irsend.sendNEC(0x41B6DD22, 32);
}
::delay(70);
currentVolume += sign;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment