// https://wokwi.com/projects/385841513818337281
// https://forum.arduino.cc/t/fader-pickup-catch-mode/1206227
# include <Adafruit_NeoPixel.h>
# define N_REAL 16
# define PIN 8
# define threshold 25 // to detect new value
// Global variables for lights and CAN communication
Adafruit_NeoPixel led(N_REAL, PIN, NEO_GRB + NEO_KHZ800);
void setup()
{
Serial.begin(115200); Serial.println("first things first");
led.begin();
led.setPixelColor(1, 0xff0000);
led.show();
delay(777);
}
bool trackA = true;
void loop()
{
static int lastA;
static int lastB;
static int output;
int valA = analogRead(A0);
int valB = analogRead(A1);
if (abs(lastA - valA) > threshold) {
lastA = valA;
if (abs(lastB - lastA) < threshold) trackA = true;
}
if (abs(lastB - valB) > threshold) {
lastB = valB;
if (abs(lastB - lastA) < threshold) trackA = false;
}
led.clear();
if (trackA) {
output = valA;
led.setPixelColor(valA / 64, 0xc00040);
}
else {
output = valA;
led.setPixelColor(valB / 64, 0x404080);
}
led.show();
}
void message(char *theMessage)
{
static unsigned int counter;
Serial.print(counter); Serial.print(" ");
Serial.println(theMessage);
counter++;
}
AAA
BBB