This newest (final!) edit brings back updating the data only when changes occur along with multiple throttle array. I have only tried with two throttles, but if you want to try more, add another element to the throttle array and give it a try.
// https://forum.arduino.cc/t/flight-sim-throttle-coding/1318665/
// two potentiometers mapped to 0 to 65 with 20 as the "idle" point
int throttle[] = {A0, A1}; // array of throttles
const int arraySize = sizeof(throttle) / sizeof(throttle[0]); // size of array
int throttleReading, throttleDegrees[arraySize], element, oldDegrees[arraySize];
#define DELAY 100 // delay between analog read
#define MININ 0 // analog input minimum value
#define MAXIN 1023 // analog input maximum balue
#define MINOUT 0 // analog input re-mapped to minimum degrees
#define MAXOUT 65 // analog input re-mapped to maximum degrees
void setup() {
Serial.begin(115200); // serial monitor communications
for (int i = 0; i < arraySize; i++)
pinMode(throttle[i], INPUT); // configure input pins
Serial.println("Move throttle A0 to IDLE (20 degrees).");
// wait for throttle to be "20 degrees"
while (map(analogRead(throttle[0]), MININ, MAXIN, MINOUT, MAXOUT) != 20);
}
void loop() {
if (element > arraySize - 1) { // count through throttle array elements
element = 0; // reset array counter
}
// Read 10 bit ADC input, 0 to 1023. Output 0 to 65 degrees
throttleReading = analogRead(throttle[element]); // 10 bit ADC = 0 to 1023
throttleDegrees[element] = map(throttleReading, MININ, MAXIN, MINOUT, MAXOUT); // output 0 to 65 degrees
if (oldDegrees[element] != throttleDegrees[element]) { // has degree changed
for (int i = 0; i < arraySize; i++) { // local variable to print all throttle traces
Serial.print(" |");
oldDegrees[i] = throttleDegrees[i]; // store new degree
Serial.print("| Trottle:"); // start trace
Serial.print(i); // throttle number
Serial.print(" |");
format(throttleDegrees[i]); // degrees output
Serial.print(throttleDegrees[i]);
Serial.print(" Degrees | ");
switch (throttleDegrees[i]) {
case 65: Serial.print("FFWD ^^"); break;
case 21 ... 64: Serial.print("fwd ^"); break;
case 20: Serial.print("IDLE =="); break;
case 1 ... 19: Serial.print("rev v"); break;
case 0: Serial.print("FREV vv"); break;
}
// Serial.print(" |"); // end of trace
if (i == arraySize - 1) // if last throttle...
Serial.println(" ||"); // ... add new line
delay(DELAY); // keep output from running off the monitor
}
}
element++; // next throttle array elemnt
}
void format(int i) { // prefix spaces
if (i > -10 && i < 0) Serial.print(" ");
if (i >= 0 && i <= 9) Serial.print(" ");
if (i > 9) Serial.print(" ");
}
diagram.json for wokwi
{
"version": 1,
"author": "Anonymous maker",
"editor": "wokwi",
"parts": [
{
"type": "wokwi-arduino-nano",
"id": "nano",
"top": 102.8,
"left": 49.3,
"rotate": 270,
"attrs": {}
},
{ "type": "wokwi-potentiometer", "id": "pot1", "top": -10.9, "left": 172.6, "attrs": {} },
{ "type": "wokwi-potentiometer", "id": "pot2", "top": -10.9, "left": 249.4, "attrs": {} }
],
"connections": [
[ "pot1:GND", "nano:GND.1", "black", [ "v19.2", "h-48" ] ],
[ "pot1:SIG", "nano:A0", "green", [ "v28.8", "h-0.4", "v94" ] ],
[ "pot1:VCC", "nano:5V", "red", [ "v38.4", "h-164" ] ],
[ "pot2:GND", "nano:GND.1", "black", [ "v19.2", "h-134.4" ] ],
[ "pot2:VCC", "nano:5V", "red", [ "v38.4", "h-164" ] ],
[ "pot2:SIG", "nano:A1", "green", [ "v28.8", "h-0.4", "v84.4" ] ]
],
"dependencies": {}
}