Turn potentiometer around

This commit is contained in:
Midgard 2022-03-17 23:50:43 +01:00
parent b14ca65bae
commit ad1463b8a6
Signed by: midgard
GPG key ID: 511C112F1331BBB4

View file

@ -40,9 +40,9 @@ uint16_t stops[] { 0, 18, 147, 526, 900, 1008, 1024 };
uint16_t getSliderValue() { uint16_t getSliderValue() {
uint16_t value = analogRead(PIN_SLIDER) + 1; uint16_t value = analogRead(PIN_SLIDER) + 1;
for (int i = 1; i < ARRAY_LENGTH(stops); i++) { for (int i = 1; i < ARRAY_LENGTH(stops); i++) {
if (value <= stops[i]) return (value - stops[i - 1]) * 170 / (stops[i] - stops[i-1]) + (i-1)*170 - 1; if (value <= stops[i]) return 1023 - ((value - stops[i - 1]) * 170 / (stops[i] - stops[i-1]) + (i-1)*170 - 1);
} }
return 0; return 1023;
} }
void gauge(unsigned char value) { void gauge(unsigned char value) {
@ -74,10 +74,18 @@ int ledCycle = 0;
void loop() { void loop() {
bool is_message_valid = obus_module::loopNeedy(&message, callback_game_start, callback_game_stop); bool is_message_valid = obus_module::loopNeedy(&message, callback_game_start, callback_game_stop);
if (!obus_module::is_active()) {
gauge(127);
delay(50);
digitalWrite(PIN_LED, 0);
return;
}
int16_t sliderValue = (getSliderValue() + previousSliderValue) / 2; int16_t sliderValue = (getSliderValue() + previousSliderValue) / 2;
previousSliderValue = getSliderValue(); previousSliderValue = getSliderValue();
int16_t gaugeValue = previousTarget - sliderValue; int16_t gaugeValue = previousTarget - sliderValue;
int32_t timeLeft = deadline - millis(); int32_t timeLeft = deadline - millis();
if (timeLeft <= ADJUSTMENT_PERIOD_MS) { if (timeLeft <= ADJUSTMENT_PERIOD_MS) {
// Require a movement being detected for at least 2 successive loops, to combat jitter // Require a movement being detected for at least 2 successive loops, to combat jitter