int prev[50] = {0};
float potHalf = 511.5;
String device[50];
void setup() {
device[A0] = "Wheel: ";
device[A1] = "Accelerator: ";
device[A2] = "Brake: ";
device[A3] = "Clutch: ";
device[A4] = "Handbrake: ";
for (int i = 0; i < 7; i++)
{
pinMode(i, OUTPUT);
digitalWrite(i, HIGH);
}
Serial.begin(250000);
}
float wheelMath(int x)
{
float num;
if (x > 512) num = ((x - potHalf) / potHalf) * 100;
else num = ((potHalf - x) / potHalf) * -100;
return num;
}
void loop() {
for (int i = A0; i < A5; i++)
{
int potvalue = analogRead(i);
while (prev[i] != potvalue)
{
prev[i] = potvalue;
Serial.print(device[i]);
if (i == A0) Serial.println(wheelMath(potvalue), 1);
else Serial.println((potvalue / 1024.0) * 100, 1);
}
}
delay(100);
}