Speed test device

Okay so what i'm trying to make in this project is a device that simulates 0-60 mph tests in cars. this device consists of:

  1. Potentiometer (Throttle).
  2. Push-button (acts as a Gear-UP button).
  3. eight LEDs (act as Rev-Lights).
  4. Seven-Segment display (displays current gear, up to Sixth gear).

i've tried Switch statements for each gear. each one of those gears has a limited value from the throttle such that if the throttle goes above that limit the code should not work unless the Gear-UP button is pushed i.e. the gear shifts into a higher position, thus increasing the said limit for the respective gear.

i tried to execute the project once but literally nothing worked. i was a bit in a rush so i'm not sure the connection was 100% okay but i wanna make sure the code works so that i can try not mess up the device.

i would really appreciate it if you look into my code and let me know if anything is not right. Thanks a lot!

Here's a bit of the code (the rest of the gears are just a matter of matching values):

byte GearUp = 2; //Gear Up button
byte BlueLED = 4; //lights up when gear is on neutral
byte G1 = 5;
byte G2 = 6;
byte G3 = 7;
byte G4 = 8;
byte Y1 = 9;
byte Y2 = 10;
byte R1 = 11;
byte R2 = 112;
const int A = 22;
const int B = 23;
const int C = 24;
const int D = 25;
const int E = 26;
const int F = 27;
const int G = 28;
const int P = 29;
int GearNum = 0;
int Rev;
int FGR; 
int SGR;
int TGR;
int FourthGR;
int FifthGR;
int SixthGR;



void setup() {
  // put your setup code here, to run once:
  pinMode(BlueLED, OUTPUT); 
  pinMode(G1, OUTPUT);
  pinMode(G2, OUTPUT);
  pinMode(G3, OUTPUT);
  pinMode(G4, OUTPUT);
  pinMode(Y1, OUTPUT);
  pinMode(Y2, OUTPUT);
  pinMode(R1, OUTPUT);
  pinMode(R2, OUTPUT);
  for(int i= A; i<=P; i++) {
    pinMode(i, OUTPUT);
    }
  Serial.begin(9600);

}

void loop() {
  // put your main code here, to run repeatedly: 
  int Reading = analogRead(A0);
Rev = map(Reading, 0, 1023, 1, 456); //rounds down to 456 to suit rev values
int Gear = digitalRead (GearUp);
int GearNum = GearNum + Gear;
switch (GearNum) {
  case 0:
 Reading = analogRead(A0);
Rev = map(Reading, 0, 1023, 1, 456);
digitalWrite(BlueLED, HIGH);
digitalWrite(A, LOW);
digitalWrite(B, LOW);
digitalWrite(C, HIGH);
digitalWrite(D, LOW);
digitalWrite(E, HIGH);
digitalWrite(F, LOW);
digitalWrite(G, HIGH);
digitalWrite(P, LOW);

break;
  case 1:
 Reading = analogRead(A0);
Rev = map(Reading, 0, 1023, 1, 456);
digitalWrite(BlueLED, LOW);
digitalWrite(A, LOW);
digitalWrite(B, HIGH);
digitalWrite(C, HIGH);
digitalWrite(D, LOW);
digitalWrite(E, LOW);
digitalWrite(F, LOW);
digitalWrite(G, LOW);
digitalWrite(P, LOW);

FGR = constrain(Rev, 1, 35); //first gear revolutions
if (FGR >= 1 && FGR <= 2) {
  digitalWrite(G1, HIGH); 
}
else if (FGR > 2 && FGR <= 4) {
  digitalWrite(G1, HIGH);
  digitalWrite(G2, HIGH);
}
else if (FGR > 4 && FGR <= 6) {
  digitalWrite(G1, HIGH);
  digitalWrite(G2, HIGH);
  digitalWrite(G3, HIGH);
}
else if (FGR > 6 && FGR <= 8) {
  digitalWrite(G1, HIGH);
  digitalWrite(G2, HIGH);
  digitalWrite(G3, HIGH);
  digitalWrite(G4, HIGH);
  
}
else if (FGR > 8 && FGR <= 12) {
  digitalWrite(G1, HIGH);
  digitalWrite(G2, HIGH);
  digitalWrite(G3, HIGH);
  digitalWrite(G4, HIGH);
  digitalWrite(Y1, HIGH);
}
else if (FGR > 12 && FGR <= 18) {
  digitalWrite(G1, HIGH);
  digitalWrite(G2, HIGH);
  digitalWrite(G3, HIGH);
  digitalWrite(G4, HIGH);
  digitalWrite(Y1, HIGH);
  digitalWrite(Y2, HIGH);
}
else if (FGR > 18 && FGR <= 26) {
  digitalWrite(G1, HIGH);
  digitalWrite(G2, HIGH);
  digitalWrite(G3, HIGH);
  digitalWrite(G4, HIGH);
  digitalWrite(Y1, HIGH);
  digitalWrite(Y2, HIGH);
  digitalWrite(R1, HIGH);
}
else if (FGR > 26 && FGR <= 35) {
  digitalWrite(G1, HIGH);
  digitalWrite(G2, HIGH);
  digitalWrite(G3, HIGH);
  digitalWrite(G4, HIGH);
  digitalWrite(Y1, HIGH);
  digitalWrite(Y2, HIGH);
  digitalWrite(R1, HIGH);
  digitalWrite(R2, HIGH);
} break;

 case 2:
 
Reading = analogRead(A0);
Rev = map(Reading, 0, 1023, 1, 456);
  digitalWrite(G1, LOW);
  digitalWrite(G2, LOW);
  digitalWrite(G3, LOW);
  digitalWrite(G4, LOW);
  digitalWrite(Y1, LOW);
  digitalWrite(Y2, LOW);
  digitalWrite(R1, LOW);
  digitalWrite(R2, LOW);
digitalWrite(A, HIGH);
digitalWrite(B, HIGH);
digitalWrite(C, LOW);
digitalWrite(D, HIGH);
digitalWrite(E, HIGH);
digitalWrite(F, LOW);
digitalWrite(G, HIGH);
digitalWrite(P, LOW);


 SGR = constrain(Rev, 36, 87); //SGR = Second Gear Revolutions
if (SGR >= 36 && SGR <= 40) {
  digitalWrite(G1, HIGH); 
}
else if (SGR > 40 && SGR <= 44) {
  digitalWrite(G1, HIGH);
  digitalWrite(G2, HIGH);
}
else if (SGR > 44 && SGR <= 48) {
  digitalWrite(G1, HIGH);
  digitalWrite(G2, HIGH);
  digitalWrite(G3, HIGH);
}
else if (SGR > 48 && SGR <= 52) {
  digitalWrite(G1, HIGH);
  digitalWrite(G2, HIGH);
  digitalWrite(G3, HIGH);
  digitalWrite(G4, HIGH);
  
}
else if (SGR > 52 && SGR <= 58) {
  digitalWrite(G1, HIGH);
  digitalWrite(G2, HIGH);
  digitalWrite(G3, HIGH);
  digitalWrite(G4, HIGH);
  digitalWrite(Y1, HIGH);
}
else if (SGR > 58 && SGR <= 66) {
  digitalWrite(G1, HIGH);
  digitalWrite(G2, HIGH);
  digitalWrite(G3, HIGH);
  digitalWrite(G4, HIGH);
  digitalWrite(Y1, HIGH);
  digitalWrite(Y2, HIGH);
}
else if (SGR > 66 && SGR <= 76) {
  digitalWrite(G1, HIGH);
  digitalWrite(G2, HIGH);
  digitalWrite(G3, HIGH);
  digitalWrite(G4, HIGH);
  digitalWrite(Y1, HIGH);
  digitalWrite(Y2, HIGH);
  digitalWrite(R1, HIGH);
}
else if (SGR > 76 && SGR <= 87) {
  digitalWrite(G1, HIGH);
  digitalWrite(G2, HIGH);
  digitalWrite(G3, HIGH);
  digitalWrite(G4, HIGH);
  digitalWrite(Y1, HIGH);
  digitalWrite(Y2, HIGH);
  digitalWrite(R1, HIGH);
  digitalWrite(R2, HIGH);


 
} break;

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html . Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

You haven't declared the GearUp pin as an INPUT in setup().

Thanks.. Tom... :slight_smile:

i wanna make sure the code works so that i can try not mess up the device.

You're probably the only person with the hardware, so testing is up to you.

If you'd developed the code alongside the hardware, only adding a new stage when the previous one was complete and tested, we wouldn't be looking (or not, in my case, because I'm on my phone) 11.66kB of code.

TomGeorge:
Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html . Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

You haven't declared the GearUp pin as an INPUT in setup().

Thanks.. Tom... :slight_smile:

Oh. well we're off to a good start.
also, sorry for the inconvenient file. i modified the post. thanks a lot!

i tried to execute the project once but literally nothing worked.

That is probably because you didn't develop each piece of the project separately, and get each working well, before putting the bits together.

It may seem surprising and bit boring, but such a methodical approach actually works!

Hi,
You need to post the entire code please.

You haven't declared the GearUp pin as an INPUT in setup().

How do you reset or change down?

Tom... :slight_smile:

Pins default to INPUT on startup. Analog inputs never need a pin mode. But it's always good practise to clearly annunciate which pins are used for which modes. I never skip writing pinMode(PIN_NAME, INPUT);