We are getting close my friends!
The code below stores and tells us the position of the retarder handle and it works perfect!
Connect the Retarder to an Arduino Leonardo:
Retarder PIN 2 to 5v
Retarder PIN 6 to gnd
Retarder PIN 7 to A0
int analogPin= 0;
int raw= 0;
int Vin= 5;
float Vout= 0;
float R1= 10000;
float R2= 0;
float buffer= 0;
void setup()
{
Serial.begin(9600);
}
void loop()
{
byte handlePos;
int val = analogRead(0);
if(val < 187)
{
handlePos = 0;
Serial.println("handlePos = 0");
Serial.println(val);
}
else if(val < 350)
{
handlePos = 1;
Serial.println("handlePos = 1");
Serial.println(val);
}
else if(val < 518)
{
handlePos = 2;
Serial.println("handlePos = 2");
Serial.println(val);
}
else if(val < 679)
{
handlePos = 3;
Serial.println("handlePos = 3");
Serial.println(val);
}
else if(val < 861)
{
handlePos = 4;
Serial.println("handlePos = 4");
Serial.println(val);
}
else if(val < 1024)
{
handlePos = 5;
Serial.println("handlePos = 5");
Serial.println(val);
}
else
{
Serial.println("handlePos unknown");
Serial.println(val);
}
delay(500);
}
// by Jeroen van der Velden
// https://hackaday.io/project/8448-real-dashboard-truck-simulator
//
Download link to Arduino IDE file
Next and final challenge: send keyboard commands "+" and "-" (retarder "up" and retarder "down")
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.